Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.5.1 #79

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
final changes
  • Loading branch information
koaning committed Aug 9, 2023
commit e449a35447cd8bc0307899048ac1efc236d59271
20 changes: 14 additions & 6 deletions docs/API/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
options:
members: false

## BytePairEncoder

::: embetter.text.BytePairEncoder
options:
members: false

## KerasNLPEncoder

::: embetter.text.KerasNLPEncoder
Expand All @@ -27,3 +21,17 @@
::: embetter.text.Sense2VecEncoder
options:
members: false

## BytePairEncoder

::: embetter.text.BytePairEncoder
options:
members: false


## GensimEncoder

::: embetter.text.GensimEncoder
options:
members: false

7 changes: 4 additions & 3 deletions embetter/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
spaCyEncoder = NotInstalled("spaCyEncoder", "spacy")

try:
from embetter.text._word2vec import Word2VecEncoder
from embetter.text._word2vec import GensimEncoder
except ModuleNotFoundError:
Word2VecEncoder = NotInstalled("Word2VecEncoder", "gensim")
GensimEncoder = NotInstalled("GensimEncoder", "gensim")

try:
from embetter.text._keras import KerasNLPEncoder
except ModuleNotFoundError:
KerasNLPEncoder = NotInstalled("KerasNLPEncoder", "keras_nlp")
Expand All @@ -35,6 +36,6 @@
"Sense2VecEncoder",
"BytePairEncoder",
"spaCyEncoder",
"Word2VecEncoder",
"GensimEncoder",
"KerasNLPEncoder",
]
2 changes: 1 addition & 1 deletion embetter/text/_word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from embetter.base import EmbetterBase


class Word2VecEncoder(EmbetterBase):
class GensimEncoder(EmbetterBase):
"""
Encodes text using a static word embedding model. The component uses gensim's default tokenizer.

Expand Down
6 changes: 3 additions & 3 deletions tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from embetter.text import (
BytePairEncoder,
SentenceEncoder,
Word2VecEncoder,
GensimEncoder,
spaCyEncoder,
)
from embetter.utils import cached
Expand All @@ -30,15 +30,15 @@ def test_word2vec(setting):
model = Word2Vec(
sentences=sentences, vector_size=vector_size, window=3, min_count=1
)
encoder = Word2VecEncoder(model, agg=setting)
encoder = GensimEncoder(model, agg=setting)
output = encoder.fit_transform(test_sentences)
assert isinstance(output, np.ndarray)
out_dim = vector_size if setting != "both" else vector_size * 2
assert output.shape == (len(test_sentences), out_dim)
# This tests whether it can load the model from disk
with tempfile.NamedTemporaryFile() as fp:
model.save(fp)
encoder = Word2VecEncoder(fp.name, agg=setting)
encoder = GensimEncoder(fp.name, agg=setting)
encoder.transform(test_sentences)
assert repr(encoder)

Expand Down