Bert-as-service: Extracting most similar words in the vocabulary

Created on 22 Dec 2018  路  2Comments  路  Source: hanxiao/bert-as-service

Prerequisites

Description

I can extract word embeddings and it works smoothly. How would one implement most similar words kind of functionality? Something like the below example from gensim for _word2vec_, _GloVe_, _fastText_ etc. :

import gensim.downloader as api
word_vectors = api.load("glove-wiki-gigaword-100")  # load pre-trained word-vectors
result = word_vectors.most_similar(positive=['woman', 'king'], negative=['man'])

Most helpful comment

hmm, it actually doesn't work in the way as you expect. Note that unlike word2vec/Glove/fastText, word embedding from BERT is contextualized, meaning that the value of woman embedding depends on the other words in the sentence, which also means that two woman can have completely different embedding values when they appear in two different sentences. This makes "most similar words" function spurious for bert-as-service

All 2 comments

hmm, it actually doesn't work in the way as you expect. Note that unlike word2vec/Glove/fastText, word embedding from BERT is contextualized, meaning that the value of woman embedding depends on the other words in the sentence, which also means that two woman can have completely different embedding values when they appear in two different sentences. This makes "most similar words" function spurious for bert-as-service

What if I want to find the most relevant words from the contextualized vector?
Like using Bert as an intent classifier and then use the contextualized vector of the intent to find related words from the vocabulary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

un-lock-me picture un-lock-me  路  3Comments

kirdin picture kirdin  路  3Comments

JulianGerhard21 picture JulianGerhard21  路  4Comments

FanyiMo picture FanyiMo  路  3Comments

zhant09 picture zhant09  路  3Comments