Answers.Body: <blockquote>
    <p><strong>Here is a good approach to achieve the task you want:</strong></p>
  </blockquote>
  
  <p><strong>Step 1-</strong> Compute the Vector representation (i.e embeddings) of all the words you want to include. There are many algorithms out there to achieve this task. </p>
  
  <p><a href="https://i.sstatic.net/Ifqc4m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ifqc4m.png" alt="Step 1- Compute Embeddings"></a></p>
  
  <p><strong>Step 2-</strong> Choose the #words corresponding to your input word (e.g dog) by applying K-Nearest Neighbors (KNN) or similar algorithms. You basically compute the distances using the embeddings.</p>
  
  <p><a href="https://i.sstatic.net/jI8Ptm.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jI8Ptm.jpg" alt="Step 2 - Apply KNN"></a></p>
  
  <blockquote>
    <p><strong>Steps Detailed:</strong></p>
  </blockquote>
  
  <p><strong>Step 1-</strong> </p>
  
  <p>In NLP we represent human language as a vector of values instead of a set of characters in order to process it. To do so there are 3 approaches in the literature:</p>
  
  <p><strong>- Word Level Embeddings:</strong> Represent each word as a vector of values.
     Algorithms: <a href="https://medium.freecodecamp.org/how-to-get-started-with-word2vec-and-then-how-to-make-it-work-d0a2fca9dad3" rel="nofollow noreferrer">Word2Vec by Google</a> (<a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf" rel="nofollow noreferrer">paper</a>), <a href="https://blog.manash.me/how-to-use-pre-trained-word-vectors-from-facebooks-fasttext-a71e6d55f27" rel="nofollow noreferrer">fastText by Facebook</a>, <a href="https://nlp.stanford.edu/projects/glove/" rel="nofollow noreferrer">GloVe by Stanford University</a> (<a href="https://nlp.stanford.edu/pubs/glove.pdf" rel="nofollow noreferrer">paper</a>) ...</p>
  
  <p><strong>- Character Level Embeddings:</strong> Represent each character as a vector of values. Algorithms: <a href="https://towardsdatascience.com/elmo-contextual-language-embedding-335de2268604" rel="nofollow noreferrer">ELMo</a> (<a href="https://arxiv.org/abs/1802.05365" rel="nofollow noreferrer">paper</a>) ...</p>
  
  <p><strong>- Sentence Level Embeddings:</strong> Represent a sentence as a vector of values. Algorithms: <a href="https://tfhub.dev/google/universal-sentence-encoder/1" rel="nofollow noreferrer">Universal Sentence Encoder by Google</a> (<a href="https://arxiv.org/abs/1803.11175" rel="nofollow noreferrer">paper</a>) ...</p>
  
  <p>In your case I suggest to use <a href="https://nlp.stanford.edu/projects/glove/" rel="nofollow noreferrer">GloVe</a> or <a href="https://towardsdatascience.com/elmo-contextual-language-embedding-335de2268604" rel="nofollow noreferrer">ElMo</a> if you have only words and <a href="https://tfhub.dev/google/universal-sentence-encoder/1" rel="nofollow noreferrer">Universal Sentence Encoder</a> if you have words and sentences.  . Compute all your words embeddings and move to the next step.</p>
  
  <p><strong>Step 2-</strong> </p>
  
  <p>Now that you have your embeddings, compute the distances between all your words <em>(use Euclidian, Minkowski or any other distance)</em>. Notice that the computation may take some time but will only be executed once. </p>
  
  <p>Now each time you have a word (e.g dog) you apply the <strong>KNN</strong> algorithm using the computed distances and you will get the most related words to this word. </p>
  
  <blockquote>
    <p><strong>Note</strong>: No need to compute distances and apply KNN if you use Universal Sentence Encoder as the similarity is easily computed using a dot product of the embeddings. See my quick implementation example <a href="https://ai.stackexchange.com/questions/4965/sentence-similarity-in-python/12232#12232">here</a> for details.  </p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T13:35:43.560Z
Answers.LastActivityDate: 2019-05-24T11:02:01.823Z
Answers.LastEditDate: 2019-05-24T11:02:01.823Z
Answers.UserDisplayName: HLeb
Answers.Body: <p>You can try using Mallet (which uses Gibs Sampling) or gensim LDA (which uses drichlet priors) to model the problem as topics (hashtags) in different documents (tweets).
  <a href="https://towardsdatascience.com/topic-modeling-and-latent-dirichlet-allocation-in-python-9bf156893c24" rel="nofollow noreferrer">https://towardsdatascience.com/topic-modeling-and-latent-dirichlet-allocation-in-python-9bf156893c24</a> has a nice example.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T07:18:52.717Z
Answers.LastActivityDate: 2018-11-09T07:18:52.717Z
Answers.UserDisplayName: jazib jamil
Answers.Body: <p>I think your intuition about a classifier being the wrong approach is a good one.  This looks like a great use-case for word vectors, a "self-supervised" learning technique that maps tokens (e.g. "dog") to vectors (which might have anywhere between 50 - 500 dimensions).  Facebook open-sourced a particular excellent tool for training word vectors <a href="https://github.com/facebookresearch/fastText" rel="nofollow noreferrer">called FastText</a>; you could use this to embed tokens and hashtags alike into a word embedding space.  You should find that the vector for "dog" ends "close to" (small cosine distance).  Given a word, you can easily look up its vector (after training on your corpus, of course), but how to find other vectors that are close to it?  If you want to do better than "brute force" and you need to check against a large number of (vectors for) hashtags, you should consider using <a href="https://github.com/facebookresearch/faiss" rel="nofollow noreferrer">Facebook's excellent FAISS library for fast similarity search</a> to find the closest hashtags.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T13:31:47.927Z
Answers.LastActivityDate: 2019-05-08T13:31:47.927Z
Answers.UserDisplayName: Edward Dixon
Body: <p>I am trying to build a neural network that takes in a single string, ex: "dog" as an input, and outputs 50 or so related hashtags such as, "#pug, #dogsarelife, #realbff".</p>
  
  <p>I have thought of using a classifier, but because there is going to be millions of hashtags to choose the optimal one from, and millions of possible words from the english dictionary, it is virtually impossible to search up the probability of each </p>
  
  <p>It is going to be learning information from analyzing twitter posts' text, and its hashtags, and find which hashtags goes with what specific words.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-22T11:45:06.037Z
Comments.Text: The problem with that is that because I am trying to analyze twitter posts, with hashtags like #follow4follow which are totally unrelated with dogs, I would need a neural network to carry out the decisions. Besides its not going to be only dogs, cats, cars, mountains, calendars, you name it.
  Basically it is supposed to work like a translator neural network, translating between "strings" and possible #hashtags
  @DuttaA
Comments.UserDisplayName: Tamim Azmain
Tags: <neural-networks><ai-design><algorithm>
Title: What machine learning algorithm should be used to analyze the relationship between strings?
UserDisplayName: Tamim Azmain
ThreadText: # What machine learning algorithm should be used to analyze the relationship between strings?
  
  (Asked by: username_0 on 2018-01-22)
  
  I am trying to build a neural network that takes in a single string, ex: "dog" as an input, and outputs 50 or so related hashtags such as, "#pug, #dogsarelife, #realbff".
  
  I have thought of using a classifier, but because there is going to be millions of hashtags to choose the optimal one from, and millions of possible words from the english dictionary, it is virtually impossible to search up the probability of each
  
  It is going to be learning information from analyzing twitter posts' text, and its hashtags, and find which hashtags goes with what specific words.
  
  **Tags:** neural-networks, ai-design, algorithm
  > **Comments:**
  > **username_0**: The problem with that is that because I am trying to analyze twitter posts, with hashtags like #follow4follow which are totally unrelated with dogs, I would need a neural network to carry out the decisions. Besides its not going to be only dogs, cats, cars, mountains, calendars, you name it. Basically it is supposed to work like a translator neural network, translating between "strings" and possible #hashtags @DuttaA  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-05-08. Score: 1
  
  > **Here is a good approach to achieve the task you want:**
  
  **Step 1-** Compute the Vector representation (i.e embeddings) of all the words you want to include. There are many algorithms out there to achieve this task.
  
  [![Step 1- Compute Embeddings](https://i.sstatic.net/Ifqc4m.png)](https://i.sstatic.net/Ifqc4m.png)
  
  **Step 2-** Choose the #words corresponding to your input word (e.g dog) by applying K-Nearest Neighbors (KNN) or similar algorithms. You basically compute the distances using the embeddings.
  
  [![Step 2 - Apply KNN](https://i.sstatic.net/jI8Ptm.jpg)](https://i.sstatic.net/jI8Ptm.jpg)
  
  > **Steps Detailed:**
  
  **Step 1-**
  
  In NLP we represent human language as a vector of values instead of a set of characters in order to process it. To do so there are 3 approaches in the literature:
  
  **- Word Level Embeddings:** Represent each word as a vector of values.
  Algorithms: [Word2Vec by Google](https://medium.freecodecamp.org/how-to-get-started-with-word2vec-and-then-how-to-make-it-work-d0a2fca9dad3) ([paper](https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf)), [fastText by Facebook](https://blog.manash.me/how-to-use-pre-trained-word-vectors-from-facebooks-fasttext-a71e6d55f27), [GloVe by Stanford University](https://nlp.stanford.edu/projects/glove/) ([paper](https://nlp.stanford.edu/pubs/glove.pdf)) ...
  
  **- Character Level Embeddings:** Represent each character as a vector of values. Algorithms: [ELMo](https://towardsdatascience.com/elmo-contextual-language-embedding-335de2268604) ([paper](https://arxiv.org/abs/1802.05365)) ...
  
  **- Sentence Level Embeddings:** Represent a sentence as a vector of values. Algorithms: [Universal Sentence Encoder by Google](https://tfhub.dev/google/universal-sentence-encoder/1) ([paper](https://arxiv.org/abs/1803.11175)) ...
  
  In your case I suggest to use [GloVe](https://nlp.stanford.edu/projects/glove/) or [ElMo](https://towardsdatascience.com/elmo-contextual-language-embedding-335de2268604) if you have only words and [Universal Sentence Encoder](https://tfhub.dev/google/universal-sentence-encoder/1) if you have words and sentences. . Compute all your words embeddings and move to the next step.
  
  **Step 2-**
  
  Now that you have your embeddings, compute the distances between all your words *(use Euclidian, Minkowski or any other distance)*. Notice that the computation may take some time but will only be executed once.
  
  Now each time you have a word (e.g dog) you apply the **KNN** algorithm using the computed distances and you will get the most related words to this word.
  
  > **Note**: No need to compute distances and apply KNN if you use Universal Sentence Encoder as the similarity is easily computed using a dot product of the embeddings. See my quick implementation example [here](https://ai.stackexchange.com/questions/4965/sentence-similarity-in-python/12232#12232) for details.
  
  
  ---
  
  ### Answer by username_2 on 2018-11-09. Score: 0
  
  You can try using Mallet (which uses Gibs Sampling) or gensim LDA (which uses drichlet priors) to model the problem as topics (hashtags) in different documents (tweets).
  <https://towardsdatascience.com/topic-modeling-and-latent-dirichlet-allocation-in-python-9bf156893c24> has a nice example.
  
  
  ---
  
  ### Answer by username_3 on 2019-05-08. Score: 0
  
  I think your intuition about a classifier being the wrong approach is a good one. This looks like a great use-case for word vectors, a "self-supervised" learning technique that maps tokens (e.g. "dog") to vectors (which might have anywhere between 50 - 500 dimensions). Facebook open-sourced a particular excellent tool for training word vectors [called FastText](https://github.com/facebookresearch/fastText); you could use this to embed tokens and hashtags alike into a word embedding space. You should find that the vector for "dog" ends "close to" (small cosine distance). Given a word, you can easily look up its vector (after training on your corpus, of course), but how to find other vectors that are close to it? If you want to do better than "brute force" and you need to check against a large number of (vectors for) hashtags, you should consider using [Facebook's excellent FAISS library for fast similarity search](https://github.com/facebookresearch/faiss) to find the closest hashtags.
  
  
  ---
  
  