import collections
import math


def get_data_stats(texts):
  """Compute the IDF score for each word. Then compute the TF-IDF score."""
  word_doc_freq = collections.defaultdict(int)
  # Compute IDF
  for text in texts:
    cur_word_dict = {}
    cur_sent = text.split(' ')
    for word in cur_sent:
      cur_word_dict[word] = 1
    for word in cur_word_dict:
      word_doc_freq[word] += 1
  idf = {}
  for word in word_doc_freq:
    idf[word] = math.log(len(texts) * 1. / word_doc_freq[word])
  # Compute TF-IDF
  tf_idf = {}
  for text in texts:
    cur_word_dict = {}
    cur_sent = text.split(' ')
    for word in cur_sent:
      if word not in tf_idf:
        tf_idf[word] = 0
      tf_idf[word] += 1. / len(cur_sent) * idf[word]
  return {
      "idf": idf,
      "tf_idf": tf_idf,
  }