Spaces:
Configuration error
Configuration error
Delete errorManager class commited by mistake
Browse files- modules/module_BiasExplorer.py +23 -25
modules/module_BiasExplorer.py
CHANGED
@@ -12,8 +12,7 @@ __all__ = ['WordBiasExplorer', 'WEBiasExplorer2Spaces', 'WEBiasExplorer4Spaces']
|
|
12 |
class WordBiasExplorer:
|
13 |
def __init__(
|
14 |
self,
|
15 |
-
embedding
|
16 |
-
errorManager # ErrorManager class instance
|
17 |
) -> None:
|
18 |
|
19 |
self.embedding = embedding
|
@@ -21,7 +20,6 @@ class WordBiasExplorer:
|
|
21 |
self.positive_end = None
|
22 |
self.negative_end = None
|
23 |
self.DIRECTION_METHODS = ['single', 'sum', 'pca']
|
24 |
-
self.errorManager = errorManager
|
25 |
|
26 |
def __copy__(
|
27 |
self
|
@@ -247,12 +245,12 @@ class WordBiasExplorer:
|
|
247 |
out_msj = ""
|
248 |
|
249 |
if not word:
|
250 |
-
out_msj =
|
251 |
else:
|
252 |
if word not in self.embedding:
|
253 |
-
out_msj =
|
254 |
|
255 |
-
return
|
256 |
|
257 |
def check_oov(
|
258 |
self,
|
@@ -269,11 +267,10 @@ class WordBiasExplorer:
|
|
269 |
class WEBiasExplorer2Spaces(WordBiasExplorer):
|
270 |
def __init__(
|
271 |
self,
|
272 |
-
embedding
|
273 |
-
errorManager # ErrorManager class instance
|
274 |
) -> None:
|
275 |
|
276 |
-
super().__init__(embedding
|
277 |
|
278 |
def calculate_bias(
|
279 |
self,
|
@@ -286,7 +283,7 @@ class WEBiasExplorer2Spaces(WordBiasExplorer):
|
|
286 |
|
287 |
for wordlist in wordlists:
|
288 |
if not wordlist:
|
289 |
-
raise Exception('
|
290 |
|
291 |
err = self.check_oov(wordlists)
|
292 |
if err:
|
@@ -371,8 +368,10 @@ class WEBiasExplorer2Spaces(WordBiasExplorer):
|
|
371 |
plt.xticks(np.arange(-most_extream_projection,
|
372 |
most_extream_projection + axis_projection_step,
|
373 |
axis_projection_step))
|
374 |
-
|
375 |
-
|
|
|
|
|
376 |
xlabel = axes_labels_format(
|
377 |
left=self.negative_end,
|
378 |
right=self.positive_end,
|
@@ -389,11 +388,10 @@ class WEBiasExplorer2Spaces(WordBiasExplorer):
|
|
389 |
class WEBiasExplorer4Spaces(WordBiasExplorer):
|
390 |
def __init__(
|
391 |
self,
|
392 |
-
embedding
|
393 |
-
errorManager # ErrorManager class instance
|
394 |
) -> None:
|
395 |
|
396 |
-
super().__init__(embedding
|
397 |
|
398 |
def calculate_bias(
|
399 |
self,
|
@@ -414,7 +412,7 @@ class WEBiasExplorer4Spaces(WordBiasExplorer):
|
|
414 |
|
415 |
for wordlist in wordlists:
|
416 |
if not wordlist:
|
417 |
-
raise Exception('
|
418 |
|
419 |
err = self.check_oov(wordlists)
|
420 |
if err:
|
@@ -504,15 +502,9 @@ class WEBiasExplorer4Spaces(WordBiasExplorer):
|
|
504 |
projections_df['projection']
|
505 |
.abs()
|
506 |
.max(),
|
507 |
-
decimals=1
|
508 |
-
|
509 |
-
|
510 |
-
sns.scatterplot(x='projection_x',
|
511 |
-
y='projection_y',
|
512 |
-
data=projections_df,
|
513 |
-
# color=list(projections_df['color'].to_list()), # No se distinguen los colores
|
514 |
-
color='blue'
|
515 |
-
)
|
516 |
|
517 |
plt.xticks(np.arange(-most_extream_projection,
|
518 |
most_extream_projection + axis_projection_step,
|
@@ -520,7 +512,13 @@ class WEBiasExplorer4Spaces(WordBiasExplorer):
|
|
520 |
for _, row in (projections_df.iterrows()):
|
521 |
ax.annotate(
|
522 |
row['word'], (row['projection_x'], row['projection_y']))
|
|
|
|
|
|
|
523 |
|
|
|
|
|
|
|
524 |
|
525 |
x_label = axes_labels_format(
|
526 |
left=name_left,
|
|
|
12 |
class WordBiasExplorer:
|
13 |
def __init__(
|
14 |
self,
|
15 |
+
embedding # Embedding Class instance
|
|
|
16 |
) -> None:
|
17 |
|
18 |
self.embedding = embedding
|
|
|
20 |
self.positive_end = None
|
21 |
self.negative_end = None
|
22 |
self.DIRECTION_METHODS = ['single', 'sum', 'pca']
|
|
|
23 |
|
24 |
def __copy__(
|
25 |
self
|
|
|
245 |
out_msj = ""
|
246 |
|
247 |
if not word:
|
248 |
+
out_msj = "Error: Primero debe ingresar una palabra!"
|
249 |
else:
|
250 |
if word not in self.embedding:
|
251 |
+
out_msj = f"Error: La palabra '<b>{word}</b>' no se encuentra en el vocabulario!"
|
252 |
|
253 |
+
return out_msj
|
254 |
|
255 |
def check_oov(
|
256 |
self,
|
|
|
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(
|
276 |
self,
|
|
|
283 |
|
284 |
for wordlist in wordlists:
|
285 |
if not wordlist:
|
286 |
+
raise Exception('Debe ingresar al menos 1 palabra en las lista de palabras a diagnosticar, sesgo 1 y sesgo 2')
|
287 |
|
288 |
err = self.check_oov(wordlists)
|
289 |
if err:
|
|
|
368 |
plt.xticks(np.arange(-most_extream_projection,
|
369 |
most_extream_projection + axis_projection_step,
|
370 |
axis_projection_step))
|
371 |
+
|
372 |
+
# xlabel = ('← {} {} {} →'.format(self.negative_end,
|
373 |
+
# ' ' * 20,
|
374 |
+
# self.positive_end))
|
375 |
xlabel = axes_labels_format(
|
376 |
left=self.negative_end,
|
377 |
right=self.positive_end,
|
|
|
388 |
class WEBiasExplorer4Spaces(WordBiasExplorer):
|
389 |
def __init__(
|
390 |
self,
|
391 |
+
embedding # Embedding Class instance
|
|
|
392 |
) -> None:
|
393 |
|
394 |
+
super().__init__(embedding)
|
395 |
|
396 |
def calculate_bias(
|
397 |
self,
|
|
|
412 |
|
413 |
for wordlist in wordlists:
|
414 |
if not wordlist:
|
415 |
+
raise Exception('¡Para graficar con 4 espacios, debe ingresar al menos 1 palabra en todas las listas!')
|
416 |
|
417 |
err = self.check_oov(wordlists)
|
418 |
if err:
|
|
|
502 |
projections_df['projection']
|
503 |
.abs()
|
504 |
.max(),
|
505 |
+
decimals=1)
|
506 |
+
sns.scatterplot(x='projection_x', y='projection_y', data=projections_df,
|
507 |
+
palette=projections_df['color'])
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
|
509 |
plt.xticks(np.arange(-most_extream_projection,
|
510 |
most_extream_projection + axis_projection_step,
|
|
|
512 |
for _, row in (projections_df.iterrows()):
|
513 |
ax.annotate(
|
514 |
row['word'], (row['projection_x'], row['projection_y']))
|
515 |
+
# x_label = '← {} {} {} →'.format(name_left,
|
516 |
+
# ' ' * 20,
|
517 |
+
# name_right)
|
518 |
|
519 |
+
# y_label = '← {} {} {} →'.format(name_top,
|
520 |
+
# ' ' * 20,
|
521 |
+
# name_bottom)
|
522 |
|
523 |
x_label = axes_labels_format(
|
524 |
left=name_left,
|