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

How to use custom word embeddings? #36

Open
havardox opened this issue Mar 17, 2023 · 1 comment
Open

How to use custom word embeddings? #36

havardox opened this issue Mar 17, 2023 · 1 comment

Comments

@havardox
Copy link

Is it possible to use custom pre-trained word embeddings? The current ones all seem to be in English and I want to load embeddings in other languages.

Relevant section of docs: https://entity-embed.readthedocs.io/en/latest/guide/field_types.html#semantic-fields

@fjsj
Copy link
Member

fjsj commented Mar 17, 2023

Yes it is if you get ones compatible with torchtext Vocab. The version of torchtext that the project uses is not the latest one, that's the issue I think.

Also note the semantic embedding part of the model is mostly straightforward:

class SemanticEmbedNet(nn.Module):
def __init__(self, field_config, embedding_size):
super().__init__()
self.embedding_size = embedding_size
self.dense_net = nn.Sequential(
nn.Embedding.from_pretrained(field_config.vocab.vectors),
nn.Dropout(p=field_config.embed_dropout_p),
)
def forward(self, x, **kwargs):
return self.dense_net(x)

You may switch that for your own semantic embedding and train as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants