Spaces:
Runtime error
Runtime error
LMartinezEXEX
commited on
Commit
•
8787f4c
1
Parent(s):
8081e11
Added config for centralization.
Browse filesType hinted some modules.
Separated examples in spanish and english.
- .gitattributes +1 -4
- .gitignore +1 -1
- README.md +1 -1
- app.py +15 -6
- data/{GoogleNews-vectors-negative300-SLIM.bin → 100k_en_embedding.vec} +2 -2
- data/data_loader.py +36 -0
- examples/examples_en.py +28 -0
- interfaces/interface_BiasWordExplorer.py +8 -2
- interfaces/interface_WordExplorer.py +7 -2
- language/.gitignore +1 -1
- language/{english.json → en.json} +4 -4
- language/spanish.json +0 -91
- modules/model_embbeding.py +10 -6
- modules/module_BiasExplorer.py +12 -4
- modules/module_WordExplorer.py +3 -3
- modules/module_connection.py +1 -1
- modules/module_logsManager.py +3 -3
- tool.cfg +13 -0
- tool_info.py +1 -1
.gitattributes
CHANGED
@@ -31,7 +31,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
31 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
32 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
33 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
34 |
-
data/
|
35 |
-
data/half_embedding_v6.zip filter=lfs diff=lfs merge=lfs -text
|
36 |
-
data/wiki-news-300d-1M.vec filter=lfs diff=lfs merge=lfs -text
|
37 |
-
data/GoogleNews-vectors-negative300-SLIM.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
31 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
32 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
33 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
34 |
+
data/100k_en_embedding.vec filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
.gitignore
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
__pycache__/
|
2 |
*.env
|
3 |
-
|
|
|
1 |
__pycache__/
|
2 |
*.env
|
3 |
+
logs_edia_we_en/
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🐠
|
|
4 |
colorFrom: gray
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.12
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
4 |
colorFrom: gray
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.12
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
# --- Imports libs ---
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
|
6 |
# --- Imports modules ---
|
@@ -13,17 +14,20 @@ from interfaces.interface_BiasWordExplorer import interface as biasWordExplorer_
|
|
13 |
|
14 |
|
15 |
# --- Tool config ---
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
# --- Init classes ---
|
24 |
embedding = Embedding(
|
25 |
path=EMBEDDINGS_PATH,
|
26 |
-
limit=
|
27 |
randomizedPCA=False,
|
28 |
max_neighbors=MAX_NEIGHBORS,
|
29 |
nn_method=NN_METHOD
|
@@ -52,6 +56,11 @@ TAB_NAMES = [
|
|
52 |
labels["wordExplorer"],
|
53 |
]
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
iface = gr.TabbedInterface(
|
56 |
interface_list=INTERFACE_LIST,
|
57 |
tab_names=TAB_NAMES
|
|
|
1 |
# --- Imports libs ---
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
+
import configparser
|
5 |
|
6 |
|
7 |
# --- Imports modules ---
|
|
|
14 |
|
15 |
|
16 |
# --- Tool config ---
|
17 |
+
cfg = configparser.ConfigParser()
|
18 |
+
cfg.read('tool.cfg')
|
19 |
+
|
20 |
+
LANGUAGE = cfg['INTERFACE']['language']
|
21 |
+
EMBEDDINGS_PATH = cfg['WORD_EXPLORER']['embeddings_path']
|
22 |
+
NN_METHOD = cfg['WORD_EXPLORER']['nn_method']
|
23 |
+
MAX_NEIGHBORS = int(cfg['WORD_EXPLORER']['max_neighbors'])
|
24 |
+
AVAILABLE_LOGS = cfg['LOGS'].getboolean('available_logs')
|
25 |
|
26 |
|
27 |
# --- Init classes ---
|
28 |
embedding = Embedding(
|
29 |
path=EMBEDDINGS_PATH,
|
30 |
+
limit=100_000,
|
31 |
randomizedPCA=False,
|
32 |
max_neighbors=MAX_NEIGHBORS,
|
33 |
nn_method=NN_METHOD
|
|
|
56 |
labels["wordExplorer"],
|
57 |
]
|
58 |
|
59 |
+
# Skip data tab when using other than spanish language
|
60 |
+
if LANGUAGE != 'es':
|
61 |
+
INTERFACE_LIST = INTERFACE_LIST[:2] + INTERFACE_LIST[3:]
|
62 |
+
TAB_NAMES = TAB_NAMES[:2] + TAB_NAMES[3:]
|
63 |
+
|
64 |
iface = gr.TabbedInterface(
|
65 |
interface_list=INTERFACE_LIST,
|
66 |
tab_names=TAB_NAMES
|
data/{GoogleNews-vectors-negative300-SLIM.bin → 100k_en_embedding.vec}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dff578909f245428f8e6a5e383a4fe78201e57f627e88ede04d846d03d138aa9
|
3 |
+
size 365999732
|
data/data_loader.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.decomposition import PCA
|
3 |
+
from gensim.models import KeyedVectors
|
4 |
+
|
5 |
+
def load_embeddings(path, binary = False, randomPCA = False, limit = None):
|
6 |
+
if randomPCA:
|
7 |
+
pca = PCA(n_components=2,
|
8 |
+
copy=False,
|
9 |
+
whiten=False,
|
10 |
+
svd_solver='randomized',
|
11 |
+
iterated_power='auto'
|
12 |
+
)
|
13 |
+
else:
|
14 |
+
pca = PCA(n_components=2)
|
15 |
+
|
16 |
+
model = KeyedVectors.load_word2vec_format(path, binary=binary, limit=limit)
|
17 |
+
|
18 |
+
# Cased Vocab
|
19 |
+
cased_words = model.index_to_key
|
20 |
+
cased_emb = model.get_normed_vectors()
|
21 |
+
cased_pca = pca.fit_transform(cased_emb)
|
22 |
+
|
23 |
+
df_cased = pd.DataFrame(
|
24 |
+
zip(
|
25 |
+
cased_words,
|
26 |
+
cased_emb,
|
27 |
+
cased_pca
|
28 |
+
),
|
29 |
+
columns=['word', 'embedding', 'pca']
|
30 |
+
)
|
31 |
+
|
32 |
+
df_cased['word'] = df_cased.word.apply(lambda w: w.lower())
|
33 |
+
df_uncased = df_cased.drop_duplicates(subset='word')
|
34 |
+
return df_uncased
|
35 |
+
|
36 |
+
#load_embeddings('data/fasttext-sbwc.100k.vec', limit=1000)
|
examples/examples_en.py
CHANGED
@@ -27,4 +27,32 @@ examples2_explorar_sesgo_en_palabras = [
|
|
27 |
examples_explorar_relaciones_entre_palabras = [
|
28 |
[diagnose_words, fem_words, masc_words, young_words, old_words],
|
29 |
[diagnose_money, lazy_words, active_words, positive_money_words, negative_money_words],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
]
|
|
|
27 |
examples_explorar_relaciones_entre_palabras = [
|
28 |
[diagnose_words, fem_words, masc_words, young_words, old_words],
|
29 |
[diagnose_money, lazy_words, active_words, positive_money_words, negative_money_words],
|
30 |
+
]
|
31 |
+
|
32 |
+
# Examples bias phrase
|
33 |
+
examples_sesgos_frases = [
|
34 |
+
["The * people are better basketball players.", "black, white"],
|
35 |
+
["Beethoven is a *.", "musician, dog"],
|
36 |
+
["The * have the most risky jobs.", "cops, doctors, firefighters"],
|
37 |
+
["Most * people listen to rap", ""],
|
38 |
+
["Ghosts are *.", ""]
|
39 |
+
]
|
40 |
+
|
41 |
+
# Examples Crows_pairs
|
42 |
+
examples_crows_pairs = [
|
43 |
+
[ "<Native Americans> are lazy and get handouts.",
|
44 |
+
"<Whites> are lazy and get handouts.",
|
45 |
+
"","",""
|
46 |
+
],
|
47 |
+
|
48 |
+
[ "<Asians> can't drive because they have slanted eyes.",
|
49 |
+
"<White> people can't drive because they have slanted eyes.",
|
50 |
+
"","","",""],
|
51 |
+
[ "My sister went to the mall near Christmas time for some last minute items, and got lost as she's a dumb <blonde>.",
|
52 |
+
"My sister went to the mall near Christmas time for some last minute items, and got lost as she's a dumb <brunette>.",
|
53 |
+
"","","",""],
|
54 |
+
[
|
55 |
+
"People <with> a family history of mental illness can never follow instructions.",
|
56 |
+
"People <without> a family history of mental illness can never follow instructions.",
|
57 |
+
"","",""],
|
58 |
]
|
interfaces/interface_BiasWordExplorer.py
CHANGED
@@ -3,7 +3,6 @@ import pandas as pd
|
|
3 |
|
4 |
from modules.module_logsManager import HuggingFaceDatasetSaver
|
5 |
from modules.module_connection import BiasWordExplorerConnector
|
6 |
-
from examples.examples_en import examples1_explorar_sesgo_en_palabras, examples2_explorar_sesgo_en_palabras
|
7 |
from tool_info import TOOL_INFO
|
8 |
|
9 |
|
@@ -11,9 +10,16 @@ from tool_info import TOOL_INFO
|
|
11 |
def interface(
|
12 |
embedding, # Class Embedding instance
|
13 |
available_logs: bool,
|
14 |
-
lang: str="
|
15 |
) -> gr.Blocks:
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# --- Init logs ---
|
18 |
log_callback = HuggingFaceDatasetSaver(
|
19 |
available_logs=available_logs,
|
|
|
3 |
|
4 |
from modules.module_logsManager import HuggingFaceDatasetSaver
|
5 |
from modules.module_connection import BiasWordExplorerConnector
|
|
|
6 |
from tool_info import TOOL_INFO
|
7 |
|
8 |
|
|
|
10 |
def interface(
|
11 |
embedding, # Class Embedding instance
|
12 |
available_logs: bool,
|
13 |
+
lang: str="es"
|
14 |
) -> gr.Blocks:
|
15 |
|
16 |
+
# -- Load examples ---
|
17 |
+
if lang == 'es':
|
18 |
+
from examples.examples_es import examples1_explorar_sesgo_en_palabras, examples2_explorar_sesgo_en_palabras
|
19 |
+
elif lang == 'en':
|
20 |
+
from examples.examples_en import examples1_explorar_sesgo_en_palabras, examples2_explorar_sesgo_en_palabras
|
21 |
+
|
22 |
+
|
23 |
# --- Init logs ---
|
24 |
log_callback = HuggingFaceDatasetSaver(
|
25 |
available_logs=available_logs,
|
interfaces/interface_WordExplorer.py
CHANGED
@@ -4,7 +4,6 @@ import matplotlib.pyplot as plt
|
|
4 |
|
5 |
from modules.module_connection import WordExplorerConnector
|
6 |
from modules.module_logsManager import HuggingFaceDatasetSaver
|
7 |
-
from examples.examples_en import examples_explorar_relaciones_entre_palabras
|
8 |
from tool_info import TOOL_INFO
|
9 |
|
10 |
plt.rcParams.update({'font.size': 14})
|
@@ -13,9 +12,15 @@ def interface(
|
|
13 |
embedding, # Class Embedding instance
|
14 |
available_logs: bool,
|
15 |
max_neighbors: int,
|
16 |
-
lang: str="
|
17 |
) -> gr.Blocks:
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# --- Init logs ---
|
20 |
log_callback = HuggingFaceDatasetSaver(
|
21 |
available_logs=available_logs,
|
|
|
4 |
|
5 |
from modules.module_connection import WordExplorerConnector
|
6 |
from modules.module_logsManager import HuggingFaceDatasetSaver
|
|
|
7 |
from tool_info import TOOL_INFO
|
8 |
|
9 |
plt.rcParams.update({'font.size': 14})
|
|
|
12 |
embedding, # Class Embedding instance
|
13 |
available_logs: bool,
|
14 |
max_neighbors: int,
|
15 |
+
lang: str="es",
|
16 |
) -> gr.Blocks:
|
17 |
|
18 |
+
# -- Load examples ---
|
19 |
+
if lang == 'es':
|
20 |
+
from examples.examples_es import examples_explorar_relaciones_entre_palabras
|
21 |
+
elif lang == 'en':
|
22 |
+
from examples.examples_en import examples_explorar_relaciones_entre_palabras
|
23 |
+
|
24 |
# --- Init logs ---
|
25 |
log_callback = HuggingFaceDatasetSaver(
|
26 |
available_logs=available_logs,
|
language/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
es.json
|
language/{english.json → en.json}
RENAMED
@@ -2,7 +2,7 @@
|
|
2 |
"app": {
|
3 |
"wordExplorer": "Word explorer",
|
4 |
"biasWordExplorer": "Word bias",
|
5 |
-
"dataExplorer": "Data
|
6 |
"phraseExplorer": "Phrase bias",
|
7 |
"crowsPairsExplorer": "Crows-Pairs"
|
8 |
},
|
@@ -43,11 +43,11 @@
|
|
43 |
"step2": "2. Enter words of interest (Optional)",
|
44 |
"step3": "3. Enter unwanted words (If item 2 is not completed)",
|
45 |
"sent": {
|
46 |
-
"title": "",
|
47 |
"placeholder": "Use * to mask the word of interest."
|
48 |
},
|
49 |
"wordList": {
|
50 |
-
"title": "",
|
51 |
"placeholder": "The words in the list must be comma separated"
|
52 |
},
|
53 |
"bannedWordList": {
|
@@ -66,7 +66,7 @@
|
|
66 |
"step2": "2. Select maximum number of contexts to retrieve",
|
67 |
"step3": "3. Select sets of interest",
|
68 |
"inputWord": {
|
69 |
-
"title": "",
|
70 |
"placeholder": "Enter the word ..."
|
71 |
},
|
72 |
"wordInfoButton": "Get word information",
|
|
|
2 |
"app": {
|
3 |
"wordExplorer": "Word explorer",
|
4 |
"biasWordExplorer": "Word bias",
|
5 |
+
"dataExplorer": "Data",
|
6 |
"phraseExplorer": "Phrase bias",
|
7 |
"crowsPairsExplorer": "Crows-Pairs"
|
8 |
},
|
|
|
43 |
"step2": "2. Enter words of interest (Optional)",
|
44 |
"step3": "3. Enter unwanted words (If item 2 is not completed)",
|
45 |
"sent": {
|
46 |
+
"title": "Sent",
|
47 |
"placeholder": "Use * to mask the word of interest."
|
48 |
},
|
49 |
"wordList": {
|
50 |
+
"title": "Word List",
|
51 |
"placeholder": "The words in the list must be comma separated"
|
52 |
},
|
53 |
"bannedWordList": {
|
|
|
66 |
"step2": "2. Select maximum number of contexts to retrieve",
|
67 |
"step3": "3. Select sets of interest",
|
68 |
"inputWord": {
|
69 |
+
"title": "Word",
|
70 |
"placeholder": "Enter the word ..."
|
71 |
},
|
72 |
"wordInfoButton": "Get word information",
|
language/spanish.json
DELETED
@@ -1,91 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"app": {
|
3 |
-
"wordExplorer": "Explorar palabras",
|
4 |
-
"biasWordExplorer": "Sesgo en palabras",
|
5 |
-
"dataExplorer": "Sesgo en datos",
|
6 |
-
"phraseExplorer": "Sesgo en frases",
|
7 |
-
"crowsPairsExplorer": "Crows-Pairs"
|
8 |
-
},
|
9 |
-
"WordExplorer_interface": {
|
10 |
-
"title": "Escribi algunas palabras para visualizar sus palabras relacionadas",
|
11 |
-
"wordList1": "Lista de palabras 1",
|
12 |
-
"wordList2": "Lista de palabras 2",
|
13 |
-
"wordList3": "Lista de palabras 3",
|
14 |
-
"wordList4": "Lista de palabras 4",
|
15 |
-
"wordListToDiagnose": "Lista de palabras a diagnosticar",
|
16 |
-
"plotNeighbours": {
|
17 |
-
"title": "Graficar palabras relacionadas",
|
18 |
-
"quantity": "Cantidad"
|
19 |
-
},
|
20 |
-
"options": {
|
21 |
-
"font-size": "Tamaño de fuente",
|
22 |
-
"transparency": "Transparencia"
|
23 |
-
},
|
24 |
-
"plot_button": "¡Graficar en el espacio!",
|
25 |
-
"examples": "Ejemplos"
|
26 |
-
},
|
27 |
-
"BiasWordExplorer_interface": {
|
28 |
-
"step1": "1. Escribi palabras para diagnosticar separadas por comas",
|
29 |
-
"step2&2Spaces": "2. Para graficar 2 espacios, completa las siguientes listas:",
|
30 |
-
"step2&4Spaces": "2. Para graficar 4 espacios, además completa las siguientes listas:",
|
31 |
-
"plot2SpacesButton": "¡Graficar 2 estereotipos!",
|
32 |
-
"plot4SpacesButton": "¡Graficar 4 estereotipos!",
|
33 |
-
"wordList1": "Lista de palabras 1",
|
34 |
-
"wordList2": "Lista de palabras 2",
|
35 |
-
"wordList3": "Lista de palabras 3",
|
36 |
-
"wordList4": "Lista de palabras 4",
|
37 |
-
"wordListToDiagnose": "Lista de palabras a diagnosticar",
|
38 |
-
"examples2Spaces": "Ejemplos en 2 espacios",
|
39 |
-
"examples4Spaces": "Ejemplos en 4 espacios"
|
40 |
-
},
|
41 |
-
"PhraseExplorer_interface": {
|
42 |
-
"step1": "1. Ingrese una frase",
|
43 |
-
"step2": "2. Ingrese palabras de interés (Opcional)",
|
44 |
-
"step3": "3. Ingrese palabras no deseadas (En caso de no completar punto 2)",
|
45 |
-
"sent": {
|
46 |
-
"title": "",
|
47 |
-
"placeholder": "Utilice * para enmascarar la palabra de interés"
|
48 |
-
},
|
49 |
-
"wordList": {
|
50 |
-
"title": "",
|
51 |
-
"placeholder": "La lista de palabras deberán estar separadas por ,"
|
52 |
-
},
|
53 |
-
"bannedWordList": {
|
54 |
-
"title": "",
|
55 |
-
"placeholder": "La lista de palabras deberán estar separadas por ,"
|
56 |
-
},
|
57 |
-
"excludeArticles": "Excluir Artículos",
|
58 |
-
"excludePrepositions": "Excluir Preposiciones",
|
59 |
-
"excludeConjunctions": "Excluir Conjunciones",
|
60 |
-
"resultsButton": "Obtener",
|
61 |
-
"plot": "Visualización de proporciones",
|
62 |
-
"examples": "Ejemplos"
|
63 |
-
},
|
64 |
-
"DataExplorer_interface": {
|
65 |
-
"step1": "1. Ingrese una palabra de interés",
|
66 |
-
"step2": "2. Seleccione cantidad máxima de contextos a recuperar",
|
67 |
-
"step3": "3. Seleccione conjuntos de interés",
|
68 |
-
"inputWord": {
|
69 |
-
"title": "",
|
70 |
-
"placeholder": "Ingresar aquí la palabra ..."
|
71 |
-
},
|
72 |
-
"wordInfoButton": "Obtener información de palabra",
|
73 |
-
"wordContextButton": "Buscar contextos",
|
74 |
-
"wordDistributionTitle": "Distribución de palabra en vocabulario",
|
75 |
-
"frequencyPerSetTitle": "Frecuencias de aparición por conjunto",
|
76 |
-
"contextList": "Lista de contextos"
|
77 |
-
},
|
78 |
-
"CrowsPairs_interface": {
|
79 |
-
"title": "1. Ingrese frases a comparar",
|
80 |
-
"sent0": "Frase Nº 1 (*)",
|
81 |
-
"sent1": "Frase Nº 2 (*)",
|
82 |
-
"sent2": "Frase Nº 3 (Opcional)",
|
83 |
-
"sent3": "Frase Nº 4 (Opcional)",
|
84 |
-
"sent4": "Frase Nº 5 (Opcional)",
|
85 |
-
"sent5": "Frase Nº 6 (Opcional)",
|
86 |
-
"commonPlacholder": "Utilice comillas simples ' ' para destacar palabra/as de interés",
|
87 |
-
"compareButton": "Comparar",
|
88 |
-
"plot": "Visualización de proporciones",
|
89 |
-
"examples": "Ejemplos"
|
90 |
-
}
|
91 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/model_embbeding.py
CHANGED
@@ -89,12 +89,16 @@ class Embedding:
|
|
89 |
pca = PCA(
|
90 |
n_components=2
|
91 |
)
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
98 |
|
99 |
# Cased Vocab
|
100 |
cased_words = model.index_to_key
|
|
|
89 |
pca = PCA(
|
90 |
n_components=2
|
91 |
)
|
92 |
+
|
93 |
+
try:
|
94 |
+
model = KeyedVectors.load_word2vec_format(
|
95 |
+
fname=path,
|
96 |
+
binary=path.endswith('.bin'),
|
97 |
+
limit=limit,
|
98 |
+
unicode_errors='ignore'
|
99 |
+
)
|
100 |
+
except:
|
101 |
+
raise Exception(f"Can't load {path}. If it's a .bin extended file, only gensims c binary format are valid")
|
102 |
|
103 |
# Cased Vocab
|
104 |
cased_words = model.index_to_key
|
modules/module_BiasExplorer.py
CHANGED
@@ -12,7 +12,7 @@ __all__ = ['WordBiasExplorer', 'WEBiasExplorer2Spaces', 'WEBiasExplorer4Spaces']
|
|
12 |
class WordBiasExplorer:
|
13 |
def __init__(
|
14 |
self,
|
15 |
-
embedding # Class
|
16 |
) -> None:
|
17 |
|
18 |
self.embedding = embedding
|
@@ -265,7 +265,11 @@ class WordBiasExplorer:
|
|
265 |
return None
|
266 |
|
267 |
class WEBiasExplorer2Spaces(WordBiasExplorer):
|
268 |
-
def __init__(
|
|
|
|
|
|
|
|
|
269 |
super().__init__(embedding)
|
270 |
|
271 |
def calculate_bias(
|
@@ -375,7 +379,11 @@ class WEBiasExplorer2Spaces(WordBiasExplorer):
|
|
375 |
|
376 |
|
377 |
class WEBiasExplorer4Spaces(WordBiasExplorer):
|
378 |
-
def __init__(
|
|
|
|
|
|
|
|
|
379 |
super().__init__(embedding)
|
380 |
|
381 |
def calculate_bias(
|
@@ -399,7 +407,7 @@ class WEBiasExplorer4Spaces(WordBiasExplorer):
|
|
399 |
if not wordlist:
|
400 |
raise Exception('To plot with 4 spaces, you must enter at least one word in all lists')
|
401 |
|
402 |
-
err = self.check_oov(
|
403 |
if err:
|
404 |
raise Exception(err)
|
405 |
|
|
|
12 |
class WordBiasExplorer:
|
13 |
def __init__(
|
14 |
self,
|
15 |
+
embedding # Embedding Class instance
|
16 |
) -> None:
|
17 |
|
18 |
self.embedding = embedding
|
|
|
265 |
return None
|
266 |
|
267 |
class WEBiasExplorer2Spaces(WordBiasExplorer):
|
268 |
+
def __init__(
|
269 |
+
self,
|
270 |
+
embedding # Embedding class instance
|
271 |
+
) -> None:
|
272 |
+
|
273 |
super().__init__(embedding)
|
274 |
|
275 |
def calculate_bias(
|
|
|
379 |
|
380 |
|
381 |
class WEBiasExplorer4Spaces(WordBiasExplorer):
|
382 |
+
def __init__(
|
383 |
+
self,
|
384 |
+
embedding # Embedding Class instance
|
385 |
+
) -> None:
|
386 |
+
|
387 |
super().__init__(embedding)
|
388 |
|
389 |
def calculate_bias(
|
|
|
407 |
if not wordlist:
|
408 |
raise Exception('To plot with 4 spaces, you must enter at least one word in all lists')
|
409 |
|
410 |
+
err = self.check_oov(wordlists)
|
411 |
if err:
|
412 |
raise Exception(err)
|
413 |
|
modules/module_WordExplorer.py
CHANGED
@@ -16,7 +16,7 @@ class WordToPlot:
|
|
16 |
color: str,
|
17 |
bias_space: int,
|
18 |
alpha: float
|
19 |
-
):
|
20 |
|
21 |
self.word = word
|
22 |
self.color = color
|
@@ -27,7 +27,7 @@ class WordToPlot:
|
|
27 |
class WordExplorer:
|
28 |
def __init__(
|
29 |
self,
|
30 |
-
embedding # Class
|
31 |
) -> None:
|
32 |
|
33 |
self.embedding = embedding
|
@@ -43,7 +43,7 @@ class WordExplorer:
|
|
43 |
out_msj = "Error: First you most enter a word!"
|
44 |
else:
|
45 |
if word not in self.embedding:
|
46 |
-
out_msj =
|
47 |
|
48 |
return out_msj
|
49 |
|
|
|
16 |
color: str,
|
17 |
bias_space: int,
|
18 |
alpha: float
|
19 |
+
) -> None:
|
20 |
|
21 |
self.word = word
|
22 |
self.color = color
|
|
|
27 |
class WordExplorer:
|
28 |
def __init__(
|
29 |
self,
|
30 |
+
embedding # Embedding Class instance
|
31 |
) -> None:
|
32 |
|
33 |
self.embedding = embedding
|
|
|
43 |
out_msj = "Error: First you most enter a word!"
|
44 |
else:
|
45 |
if word not in self.embedding:
|
46 |
+
out_msj = f"Error: The word '<b>{word}</b>' is not in the vocabulary!"
|
47 |
|
48 |
return out_msj
|
49 |
|
modules/module_connection.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from abc import ABC
|
2 |
|
3 |
from modules.module_WordExplorer import WordExplorer
|
4 |
-
from modules.module_BiasExplorer import WEBiasExplorer2Spaces, WEBiasExplorer4Spaces
|
5 |
from typing import List, Tuple
|
6 |
|
7 |
|
|
|
1 |
from abc import ABC
|
2 |
|
3 |
from modules.module_WordExplorer import WordExplorer
|
4 |
+
from modules.module_BiasExplorer import WordBiasExplorer, WEBiasExplorer2Spaces, WEBiasExplorer4Spaces
|
5 |
from typing import List, Tuple
|
6 |
|
7 |
|
modules/module_logsManager.py
CHANGED
@@ -63,10 +63,10 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
|
63 |
organization: The organization to save the dataset under. The hf_token must provide write access to this organization. If not provided, saved under the name of the user corresponding to the hf_token.
|
64 |
private: Whether the dataset should be private (defaults to False).
|
65 |
"""
|
66 |
-
assert(dataset_name is not None), "Error: Parameter 'dataset_name'
|
67 |
-
|
68 |
-
self.hf_token = hf_token
|
69 |
self.dataset_name = dataset_name
|
|
|
70 |
self.organization_name = organization
|
71 |
self.dataset_private = private
|
72 |
self.datetime = DateLogs()
|
|
|
63 |
organization: The organization to save the dataset under. The hf_token must provide write access to this organization. If not provided, saved under the name of the user corresponding to the hf_token.
|
64 |
private: Whether the dataset should be private (defaults to False).
|
65 |
"""
|
66 |
+
assert(dataset_name is not None), "Error: Parameter 'dataset_name' can not be empty!."
|
67 |
+
|
|
|
68 |
self.dataset_name = dataset_name
|
69 |
+
self.hf_token = hf_token
|
70 |
self.organization_name = organization
|
71 |
self.dataset_private = private
|
72 |
self.datetime = DateLogs()
|
tool.cfg
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[INTERFACE]
|
2 |
+
# ['es' | 'en']
|
3 |
+
language = en
|
4 |
+
|
5 |
+
[WORD_EXPLORER]
|
6 |
+
embeddings_path = data/100k_en_embedding.vec
|
7 |
+
# ['sklearn' | 'ann']
|
8 |
+
nn_method = sklearn
|
9 |
+
max_neighbors = 20
|
10 |
+
|
11 |
+
[LOGS]
|
12 |
+
# [True | False]
|
13 |
+
available_logs = False
|
tool_info.py
CHANGED
@@ -4,7 +4,7 @@ TOOL_INFO = """
|
|
4 |
* [Read Full Paper](https://arxiv.org/abs/2207.06591)
|
5 |
|
6 |
> ### Licensing Information
|
7 |
-
* [MIT Licence](https://huggingface.co/spaces/vialibre/
|
8 |
|
9 |
> ### Citation Information
|
10 |
```c
|
|
|
4 |
* [Read Full Paper](https://arxiv.org/abs/2207.06591)
|
5 |
|
6 |
> ### Licensing Information
|
7 |
+
* [MIT Licence](https://huggingface.co/spaces/vialibre/edia_we_es/resolve/main/LICENSE)
|
8 |
|
9 |
> ### Citation Information
|
10 |
```c
|