-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4380ff4
commit 4c3e71c
Showing
5 changed files
with
25 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from typing import List, Optional | ||
|
||
import torch | ||
|
||
# Please run `pip install -U sentence-transformers` | ||
from sentence_transformers import SentenceTransformer | ||
from torch import Tensor | ||
|
||
|
||
class GloveTextEmbedding: | ||
|
||
def __init__(self, device: Optional[torch.device] = None): | ||
self.model = SentenceTransformer( | ||
"sentence-transformers/average_word_embeddings_glove.6B.300d", | ||
device=device) | ||
"sentence-transformers/average_word_embeddings_glove.6B.300d", device=device | ||
) | ||
|
||
def __call__(self, sentences: List[str]) -> Tensor: | ||
return torch.from_numpy(self.model.encode(sentences)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters