Upload fle.py with huggingface_hub
Browse files
fle.py
CHANGED
|
@@ -50,11 +50,11 @@ class FLE:
|
|
| 50 |
return [(self.words[i], float(sims[i])) for i in top]
|
| 51 |
|
| 52 |
def analogy(self, a, b, c, n=5):
|
| 53 |
-
"""a is to b as c is to ? (
|
| 54 |
for w in [a, b, c]:
|
| 55 |
if w not in self.word2id:
|
| 56 |
return []
|
| 57 |
-
vec = self.normed[self.word2id[
|
| 58 |
vec = vec / (np.linalg.norm(vec) + 1e-8)
|
| 59 |
sims = self.normed @ vec
|
| 60 |
for w in [a, b, c]:
|
|
|
|
| 50 |
return [(self.words[i], float(sims[i])) for i in top]
|
| 51 |
|
| 52 |
def analogy(self, a, b, c, n=5):
|
| 53 |
+
"""a is to b as c is to ? (a - b + c)"""
|
| 54 |
for w in [a, b, c]:
|
| 55 |
if w not in self.word2id:
|
| 56 |
return []
|
| 57 |
+
vec = self.normed[self.word2id[a]] - self.normed[self.word2id[b]] + self.normed[self.word2id[c]]
|
| 58 |
vec = vec / (np.linalg.norm(vec) + 1e-8)
|
| 59 |
sims = self.normed @ vec
|
| 60 |
for w in [a, b, c]:
|