Skip to content

Commit 03c4f5a

Browse files
committed
started tuto on semantic networks
1 parent a6e7977 commit 03c4f5a

14 files changed

Lines changed: 1826 additions & 227 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
2-
src/main/asciidoc/subdir/
2+
src/main/asciidoc/subdir/
3+
properties/

docs/generated-html/working-with-text-en.html

Lines changed: 899 additions & 0 deletions
Large diffs are not rendered by default.
221 KB
Binary file not shown.

docs/generated-slides/subdir/working-from-the-source-en_temp_common.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ last modified: {docdate}
88
:iconsfont: font-awesome
99
:revnumber: 1.0
1010
:example-caption!:
11+
:sourcedir: ../../../main/java
1112

1213
:title-logo-image: gephi-logo-2010-transparent.png[width="450" align="center"]
1314

docs/generated-slides/subdir/working-from-the-source-en_temp_html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ video::Y3jk-_QaFx4[youtube, height=315, width=560, align="center"]
5353

5454
//ST: !
5555

56-
For this tutorial you need:
56+
For this tutorial you will need:
5757

5858
- some knowledge of Java.
5959

docs/generated-slides/subdir/working-from-the-source-en_temp_pdf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ link to animated version: https://www.youtube.com/watch?v=Y3jk-_QaFx4
5353

5454
//ST: !
5555

56-
For this tutorial you need:
56+
For this tutorial you will need:
5757

5858
- some knowledge of Java.
5959

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
= Working with text in Gephi
2+
Clément Levallois <clementlevallois@gmail.com>
3+
2017-02-28
4+
5+
last modified: {docdate}
6+
7+
:icons!:
8+
:iconsfont: font-awesome
9+
:revnumber: 1.0
10+
:example-caption!:
11+
12+
:title-logo-image: gephi-logo-2010-transparent.png[width="450" align="center"]
13+
14+
image::gephi-logo-2010-transparent.png[width="450" align="center"]
15+
{nbsp} +
16+
17+
//ST: 'Escape' or 'o' to see all sides, F11 for full screen, 's' for speaker notes
18+
19+
== Presentation of this tutorial
20+
//ST: Presentation of this tutorial
21+
22+
//ST: !
23+
This tutorial explains how to draw "semantic networks" like this one:
24+
25+
image::en/cooccurrences-computer/gephi-result-1-en.png[align="center", title="a semantic network"]
26+
{nbsp} +
27+
28+
We call "semantic network" a visualization where textual items (words, expressions) are connected to each others, like above.
29+
30+
//ST: !
31+
We will see in turn:
32+
33+
- why are semantic networks interesting
34+
- how to create a semantic network
35+
- tips and tricks to visualize semantic networks in the best possible way in Gephi
36+
37+
38+
== Why semantic networks?
39+
//ST: Why semantic networks?
40+
41+
A text, or many texts, can be hard to summarize.
42+
43+
Drawing a semantic network highlights what are the most frequent terms, how they relate to each other, and reveal the different groups or "clusters" of they form.
44+
45+
Often, a cluster of terms characterizes a topic. Hence, converting a text into a semantic network helps detecting topics in the text, from micro-topics to the general themes discussed in the documents.
46+
47+
//ST: !
48+
49+
Semantic networks are regular networks, where:
50+
51+
- nodes are words ("USA") or groups of words ("United States of America")
52+
53+
- relations are, usually, signifying a co-occurrences: two words are connected if they co-occur.
54+
55+
It means that if you have a textual network, you can visualize it with Gephi just like any other network. Yet, not everything is the same, and this tutorial provides tips and tricks on why textual data can be a bit different than other data.
56+
57+
//ST: !
58+
== Choosing what a "term" is in a semantic network
59+
//ST: !
60+
61+
The starting point can be: a term is a single word. So in this sentence, we would have 7 terms:
62+
63+
64+
My sister lives in the United States (7 words -> 7 terms)
65+
66+
This means that each single term is a meaningful semantic unit.
67+
68+
This approach is simple but not great. Look again at the sentence:
69+
70+
//ST: !
71+
72+
My sister lives in the United States
73+
74+
1. `My`, `in`, `the` are frequent terms which have no special significance: they should probably be discarded
75+
2. `United` and `States` are meaningful separately, but here they should probably be considered together: `United States`
76+
3. `lives` is the conjugated form of the verb `to live`. In a network, it would make sense to regroup `live`, `lives` and `lived` as one single node.
77+
78+
Analysts, facing each of these issues, have imagined several solutions:
79+
80+
//ST: !
81+
==== 1. Removing "stopwords"
82+
//ST: !
83+
84+
To remove these little terms without informational value, the most basic approach is to keep a list of them, and remove any word from the text which belongs to this list.
85+
86+
You can find a list of these useless terms in many languages, called "stopwords", http://www.ranks.nl/stopwords/[on this website].
87+
88+
//ST: !
89+
[start=2]
90+
==== 2. Considering "n-grams"
91+
//ST: !
92+
93+
So, `United States` should probably be a meaningful unit, not just `United` and `States`. Because `United States` is composed of 2 terms, it is called a "bi-gram".
94+
95+
Trigrams are interesting as well obviously (eg, `chocolate ice cream`).
96+
97+
People often stop there, but I find quadrigrams can be meaningful as well, if less frequent: `United States of America`, `functional magnetic resonance imaging`, `The New York Times`, etc.
98+
99+
Many tools exist to extract n-grams from texts, for example http://homepages.inf.ed.ac.uk/lzhang10/ngram.html[these programs which are under a free license].
100+
101+
//ST: !
102+
[start=2]
103+
==== 2 bis. Considering "noun phrases"
104+
//ST: !
105+
106+
Another approach to go beyond single word terms (`United`, `States`) takes a different approach than n-grams. It says:
107+
108+
"delete all in the text except for all groups of words made of nouns and adjectives, ending by a noun"
109+
110+
-> (these are called, a bit improperly, "noun phrases")
111+
112+
Take `United States`: it is a noun (`States`) preceded by an adjective (`United`). It will be considered as a valid term.
113+
114+
//ST: !
115+
116+
This approach is interesting (implemented for example in the software http://www.vosviewer.com[Vosviewer]), but it has drawbacks:
117+
118+
- you need to detect adjectives and nouns in your text. This is very language dependent, and slow for large corpora.
119+
120+
- what about verbs, and noun phrases comprising non adjectives, such as "United States *of* America"? These are not included in the network.
121+
122+
//ST: !
123+
[start=3]
124+
==== 3. Stemming and lemmatization
125+
//ST: !
126+
127+
`live`, `lives`, `lived`: in a semantic network, it is probably useless to have 3 nodes, one for each of these 3 forms of the same root.
128+
129+
- Stemming consists in chopping the end of the words, so that here, we would have only `live`.
130+
- Lemmatization is the same, but in a more subtle way: it takes grammar into account. So, "good" and better" would be reduced to "good" because there is the same basic semantic unit behind these two words, even if their lettering differ completely.
131+
132+
A tool performing lemmatization is https://textgrid.de/en/[TextGrid]. It has many functions for textual analysis, and lemmatization https://wiki.de.dariah.eu/display/TextGrid/The+Lemmatizer+Tool[is explained there].
133+
134+
135+
//ST: !
136+
== Should we represent all terms in a semantic network?
137+
138+
//ST: !
139+
We have seen that some words are more interesting than others in a corpus:
140+
141+
- stopwords should be removed,
142+
- some varieties of words (`lived`, `lives`) could be grouped together (`live`).
143+
- sequences of words (`baby phone`) can be added because they mean more than their words taken separately (`baby`, `phone`)
144+
145+
//ST: !
146+
Once this is done, we have transformed the text into plenty of words to represent. Should they all be included in the network?
147+
148+
Imagine we have a word appearing just once, in a single footnote of a text long of 2,000 pages. Should this word appear? Probably not.
149+
150+
Which rule to apply to keep or leave out a word?
151+
152+
//ST: !
153+
==== 1. Start with: how many words can fit in your visualization?
154+
//ST: !
155+
156+
A starting point can be the number of words you would like to see on a visualization. *A ball park figure is 300 words max*:
157+
158+
- it already fills in all the space of a computer screen.
159+
- 300 words provides enough information to allow micro-topics of a text to be distinguished
160+
161+
More words can be crammed in, but in this case the viewer would have to take time zooming in and out, panning to explore the visualization. The viewer transforms into an analyst, instead of a regular reader.
162+
163+
//ST: !
164+
==== 2. Representing only the most frequent terms
165+
//ST: !
166+
167+
If ~ 300 words would fit in the visualization of the network, and the text you start with contains 5,000 different words: which 300 words should be selected?
168+
169+
To visualize the semantic network *for a long, single text* the straightforward approach consists in picking the 300 most frequent words (or n-grams, see above).
170+
171+
172+
In the case of a colection of texts to visualize (several documents instead of one), two possibilities:
173+
//ST: !
174+
175+
1. Either you also take the most frequent terms across these documents, like before
176+
177+
2. Or you can apply a more subtle rule called "tf-idf", detailed below.
178+
179+
//ST: tf-idf
180+
181+
The idea with tf-idf is that terms which appear in all documents are not interesting, because they are so ubiquitous.
182+
183+
Example: you retrieve all the webpages mentioning the word `Gephi`, and then want to visualize the semantic network of the texts contained in these webpages.
184+
185+
//ST: !
186+
187+
-> by definition, all these webpages will mention Gephi, so Gephi will probably be the most frequent term.
188+
189+
-> so your network will end up with a node "Gephi" connected to many other terms, but you actually knew that. Boring.
190+
191+
-> terms used in all web pages are less interesting to you than terms which are used frequently, but not uniformly accross webpages.
192+
193+
//ST: !
194+
195+
Applying the tf-idf correction will highlight terms which are frequently used within some texts, but not used in many texts.
196+
197+
(to go further, here is a webpage giving a simple example: http://www.tfidf.com/)
198+
199+
//ST: !
200+
Should you visualize the most frequent words in your corpus, or the words which rank highest according to tf-idf?
201+
202+
Both are interesting, as they show a different info. I'd suggest that the simple frequency count is easier to interpret.
203+
204+
tf-idf can be left for specialists of the textual data under consideration, after they have been presented with the simple frequency count version.
205+
206+
== (to be continued)
207+
//ST: (to be continued)
208+
209+
210+
== More tutorials on importing data to Gephi
211+
//ST: More tutorials on importing data to Gephi
212+
//ST: !
213+
214+
- https://github.com/gephi/gephi/wiki/Import-CSV-Data[The Gephi wiki on importing csv]
215+
- https://www.youtube.com/watch?v=3Im7vNRA2ns[Video "How to import a CSV into Gephi" by Jen Golbeck]
216+
217+
== the end
218+
219+
//ST: The end!
220+
Visit https://www.facebook.com/groups/gephi/[the Gephi group on Facebook] to get help,
221+
222+
or visit https://seinecle.github.io/gephi-tutorials/[the website for more tutorials]

0 commit comments

Comments
 (0)