You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @DanielBeck93,
At the moment this wrapper library did not allow to set the vectors, it provided only a read-only copy of the values from TensorFlow Hub.
Given your example, I understood that the feature is quite easy to be provided.
With the new v0.4.2, you can achieve setting any vectors to tokens, spans and even entire docs.
The comparison is done on the string that you pass to the vocab.set_vector function. Only exact matches will count.
importspacy_universal_sentence_encodernlp_use=spacy_universal_sentence_encoder.load_model('en_use_lg')
vector=nlp_use('her').vectornlp_use.vocab.set_vector("Ertha", vector)
# compare the vectors, now they are equalprint((vector==nlp_use("Ertha").vector).all())
Please note that changing the vector to a single word does not change the vector of the spans/sentences/documents containing it.
If you try to compare the sentences "good for her" and "good for Ertha", they will be different, even if you have set the value of "Ertha" to be equal to "her". This happens because the USE model isn't a simple average of the word embeddings.
If you want to substitute the words in the document, my suggestion would be to substitute the string "Ertha" with "her" in the text before creating the document with nlp_use(text).
When I try to change the word embeddings nothing happens
`
import spacy_universal_sentence_encoder
nlp_use = spacy_universal_sentence_encoder.load_model('en_use_lg')
vector = nlp_use('her').vector
nlp_use.vocab.set_vector("Ertha", vector)
print(vector)
print(nlp_use("Ertha"))
`
The two print statements should be equal.
The text was updated successfully, but these errors were encountered: