text: import torch
  from torchtext.vocab import build_vocab_from_iterator
  from sentiment_anomaly.db import session
  from sentiment_anomaly.vectors import CommentsWords
  
  
  def train_torch_vocab(vectors=None, dim=50):
      """
      Build a Vocab for use with pytorch
      With vectors generated by CoreNLP GloVe as below
      dimension is 50 by default
      """
      vocab = build_vocab_from_iterator(CommentsWords(session()))
  
      if vectors:
          with open(vectors, 'r') as vect_in:
              dct, vect = vects(vect_in.readlines())
              vocab.set_vectors(dct, vect, dim)
  
      return vocab
  
  
  def vects(lines):
      """Convert CoreNLP vector text into dict with list"""
      word_index = {}
      vectors = []
  
      for index, line in enumerate(lines):
          parts = line.strip().split(' ')
          word = parts[0]
          word_index[word] = index
          vectors.append(torch.tensor([float(num) for num in parts[1:]]))
  
      return word_index, vectors
  
  
  def glove_corenlp_text():
      """If we want to train reusable GloVe vectors with demo.sh
      https://github.com/stanfordnlp/GloVe
      then it wants a single file, space separated words
      Feed this output to demo.sh instead of the demo data,
      add the resulting vectors.txt to root of this project
      """
      with open('singlefile.txt', 'w') as singlefile:
          for words in CommentsWords(session()):
              singlefile.write(' '.join(words) + ' ')
  