In [1]:
import sys
sys.path.append("..")
import seaborn as sns
%matplotlib inline
sns.set(rc={'image.cmap': 'Purples_r'})
First object is the vocabulary. It represents a lexical description of objects. That is to say, associations between $\textit{words}$ and $\textit{meanings}$. Here we consider vocabularies as being matrices filled with 0s or 1s, of size (#meanings,#words). The words and meanings are here symbolic, it means they can be refered to only by their respective column (for words) or line (for meanings) number in the matrix.
In [2]:
from naminggamesal import ngvoc
We create an object vocabulary, of type sparse (more info on other possibilities: Design_newVocabulary.ipynb), and size M=5,W=10
In [3]:
voc_cfg={
'voc_type':'lil_matrix',
'M':5,
'W':10
}
voctest=ngvoc.Vocabulary(**voc_cfg)
In [4]:
voctest
Out[4]:
It is initiated completely empty.
In [5]:
print(voctest)
In [6]:
voctest.add(0,1,1)
print(voctest)
To remove the link, simply add it with value 0.
In [7]:
voctest.add(3,4,0)
print(voctest)
Let's fill the entire matrix with ones
In [8]:
voctest.fill()
print(voctest)
We can remove homonyms or synonyms of a meaning/word association
In [9]:
voctest.rm_hom(2,2)
print(voctest)
In [10]:
voctest.fill()
voctest.rm_syn(3,4)
print(voctest)
Such as finding special subsets of meanings or words, and picking meanings and words among them. First we initialize a random vocabulary, and then apply all the functions.
Note: Small values of M and W let you see more clearly what's happening locally, high values may be more interesting for the visualizations.
In [11]:
import random
import matplotlib.pyplot as plt
voc_cfg2={
'voc_type':'lil_matrix',
'M':5,
'W':10
}
nlink=10
voctest2=ngvoc.Vocabulary(**voc_cfg2)
for i in range(0,nlink):
voctest2.add(random.randint(0, voc_cfg2['M']-1),random.randint(0, voc_cfg2['W']-1),round(random.random(),3))
print(voctest2)
Here you can modify the $voctest2$ variable by hand before executing the code:
In [12]:
#voctest2.add(0,0,1)
#voctest2.add(0,0,0)
In [13]:
print("Vocabulary:")
print(voctest2)
print("")
print("Known words:")
print(voctest2.get_known_words())
print("Random known word:")
print(voctest2.get_random_known_w())
print("")
print("Unknown words:")
print(voctest2.get_unknown_words())
print("New unknown word:")
print(voctest2.get_new_unknown_w())
print("")
print("Known meanings:")
print(voctest2.get_known_meanings())
print("Random known meaning:")
print(voctest2.get_random_known_m())
print("")
print("Unknown meanings:")
print(voctest2.get_unknown_meanings())
print("New unknown meaning:")
print(voctest2.get_new_unknown_m())
print("")
print("")
print("Known words for meaning 1:")
print(voctest2.get_known_words(1))
print("Random known word for meaning 1:")
print(voctest2.get_random_known_w(1))
print("")
print("Unknown words for meaning 1:")
print(voctest2.get_unknown_words(1))
print("")
print("Known meanings for word 2:")
print(voctest2.get_known_meanings(2))
print("Random known meaning for word 2:")
print(voctest2.get_random_known_m(2))
print("")
print("Unknown meanings for word 2:")
print(voctest2.get_unknown_meanings(2))
We introduce here a representation of the degree of synonymy/homonymy of the vocabulary. Colors are the same on a line/column. Light colors indicate high degree of synonymy/homonymy, dark ones low degree.
In [14]:
voctest2._cache
Out[14]:
In [15]:
voctest2.visual(vtype="hom")
plt.figure()
voctest2.visual(vtype="syn")
In [ ]:
In [ ]:
In [ ]: