input: Write a python function to generate a summary of a given text using nltk, which scores sentences based on word frequencies and selects the top 2 sentences.
  assert summarize_text('This is a sample text document. It contains some words about some things') == 'This is a sample text document. It contains some words about some things. '
  assert summarize_text('The quick brown fox jumps over the lazy dog. The dog was not amused. The fox ran away quickly.') == 'The quick brown fox jumps over the lazy dog. The fox ran away quickly. '
  assert summarize_text('In a distant land, there was a small village. The village was known for its beautiful landscapes. Many tourists visited the village each year.') == 'In a distant land, there was a small village. The village was known for its beautiful landscapes. '
output: def summarize_text(text):
      import nltk
      from nltk.tokenize import sent_tokenize, word_tokenize
      from nltk.corpus import stopwords
      from collections import defaultdict
  
      nltk.download('punkt')
      nltk.download('stopwords')
  
      sentences = sent_tokenize(text)
      if len(sentences) <= 2:
          return text
  
      stop_words = set(stopwords.words('english'))
      word_frequencies = defaultdict(int)
  
      for sentence in sentences:
          words = word_tokenize(sentence.lower())
          for word in words:
              if word.isalnum() and word not in stop_words:
                  word_frequencies[word] += 1
  
      sentence_scores = defaultdict(int)
      for sentence in sentences:
          for word in word_tokenize(sentence.lower()):
              if word in word_frequencies:
                  sentence_scores[sentence] += word_frequencies[word]
  
      sorted_sentences = sorted(sentences, key=lambda s: sentence_scores[s], reverse=True)
      summary = ' '.join(sorted_sentences[:2])
  
      return summary