Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. def avg_title_vec(record, lookup):
  2. avg_vec = []
  3. word_vectors = []
  4. for tag in record['all_titles']:
  5. titles = clean_token(tag).split()
  6. for word in titles:
  7. if word in lookup.value:
  8. word_vectors.append(lookup.value[word])
  9. if len(word_vectors):
  10. avg_vec = [
  11. float(val) for val in numpy.mean(
  12. numpy.array(word_vectors),
  13. axis=0)]
  14.  
  15. output = (record['id'],
  16. ','.join([str(a) for a in avg_vec]))
  17. return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement