Answers.Body: <p>I'd suggest <a href="https://arxiv.org/abs/1810.04805" rel="nofollow noreferrer">BERT</a> for this. It is essentially a word-embedding model that uses at local context to determine the appropriate embedding for each word. This means it would assign &quot;bat&quot; a different embedding in a sentence containing &quot;hit the ball&quot; vs. a sentence containing &quot;flies and eats bugs&quot;. On top of that, Google has released a number of pre-trained versions of BERT, which can be used directly without additional training (depending on your task of course). <a href="https://github.com/hanxiao/bert-as-service" rel="nofollow noreferrer">BERT as a service</a> is great if you just want embeddings. The Python <a href="https://huggingface.co/transformers/model_doc/bert.html#bertmodel" rel="nofollow noreferrer">transformers library</a> makes it exceedingly simple to incorporate BERT into your task-specific model.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-28T03:12:14.613Z
Answers.Text: Could you please elaborate on how to utilise BERT? Which functions to use to achieve the task outlined?
  
  From what I've read, BERT isn't good for cosine similarity. So how can this be used?
Answers.UserDisplayName: Yoker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-02T16:18:09.013Z
Answers.Text: Sorry I think I misunderstood your use-case the first time around. It seems you want to match tokens in context to dictionary definitions? This is a non-trivial problem. You're right that BERT may not be the best choice because the embeddings for the same word change depending on context. Autoextend may work. You may also use BERT to average the embeddings for the words of the same definition on a corpus where the ground truth meanings are known and annotated, then for new sentences compute the cosine sim between the new occurrence of the word and the averaged embedding.
Answers.UserDisplayName: primussucks
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-23T17:01:32.013Z
Answers.LastActivityDate: 2021-02-23T17:01:32.013Z
Answers.UserDisplayName: primussucks
Body: <blockquote>
  <p>The boy lifted the bat and hit the ball.</p>
  </blockquote>
  <p>In the above sentence, the noun &quot;bat&quot; means the wooden stick. It does not mean bat, the flying mammal, which is also a noun. Using NLP libraries to find the noun version of the definition would still be ambiguous.</p>
  <p>How would one go about writing an algorithm that gets the exact definition, given a word, and the sentence it is used in?</p>
  <p>I was thinking you could use word2vec, then use autoextend <a href="https://arxiv.org/pdf/1507.01127.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1507.01127.pdf</a> to differentiate between 2 different lexemes e.g. bat (animal) and bat (wooden stick).</p>
  <p>Then the closest cosine distance between the dictionary definition and any of the words of the sentence might indicate the correct definition.</p>
  <p>Does this sound correct?</p>
  
Tags: <natural-language-processing><natural-language-understanding><word2vec><semantic-networks>
Title: How would one disambiguate between two meanings of the same word in a sentence?
UserDisplayName: Yoker
ThreadText: # How would one disambiguate between two meanings of the same word in a sentence?
  
  (Asked by: username_0 on 2021-02-10)
  
  > The boy lifted the bat and hit the ball.
  
  In the above sentence, the noun "bat" means the wooden stick. It does not mean bat, the flying mammal, which is also a noun. Using NLP libraries to find the noun version of the definition would still be ambiguous.
  
  How would one go about writing an algorithm that gets the exact definition, given a word, and the sentence it is used in?
  
  I was thinking you could use word2vec, then use autoextend <https://arxiv.org/pdf/1507.01127.pdf> to differentiate between 2 different lexemes e.g. bat (animal) and bat (wooden stick).
  
  Then the closest cosine distance between the dictionary definition and any of the words of the sentence might indicate the correct definition.
  
  Does this sound correct?
  
  **Tags:** natural-language-processing, natural-language-understanding, word2vec, semantic-networks
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-23. Score: 1
  
  I'd suggest [BERT](https://arxiv.org/abs/1810.04805) for this. It is essentially a word-embedding model that uses at local context to determine the appropriate embedding for each word. This means it would assign "bat" a different embedding in a sentence containing "hit the ball" vs. a sentence containing "flies and eats bugs". On top of that, Google has released a number of pre-trained versions of BERT, which can be used directly without additional training (depending on your task of course). [BERT as a service](https://github.com/hanxiao/bert-as-service) is great if you just want embeddings. The Python [transformers library](https://huggingface.co/transformers/model_doc/bert.html#bertmodel) makes it exceedingly simple to incorporate BERT into your task-specific model.
  
  > **Comments:**
  > **username_0**: Could you please elaborate on how to utilise BERT? Which functions to use to achieve the task outlined?  From what I've read, BERT isn't good for cosine similarity. So how can this be used?  
  > **username_1**: Sorry I think I misunderstood your use-case the first time around. It seems you want to match tokens in context to dictionary definitions? This is a non-trivial problem. You're right that BERT may not be the best choice because the embeddings for the same word change depending on context. Autoextend may work. You may also use BERT to average the embeddings for the words of the same definition on a corpus where the ground truth meanings are known and annotated, then for new sentences compute the cosine sim between the new occurrence of the word and the averaged embedding.  
  
  ---
  
  