code: def test_compute_perplexity():
      from flair.embeddings import FlairEmbeddings
  
      language_model = FlairEmbeddings(
          "news-forward-fast", has_decoder=True
      ).lm
  
      grammatical = "The company made a profit"
      perplexity_gramamtical_sentence = (
          language_model.calculate_perplexity(grammatical)
      )
  
      ungrammatical = "Nook negh qapla!"
      perplexity_ungramamtical_sentence = (
          language_model.calculate_perplexity(ungrammatical)
      )
  
      print(
          f'"{grammatical}" - perplexity is {perplexity_gramamtical_sentence}'
      )
      print(
          f'"{ungrammatical}" - perplexity is {perplexity_ungramamtical_sentence}'
      )
  
      assert (
          perplexity_gramamtical_sentence
          < perplexity_ungramamtical_sentence
      )
  
      language_model = FlairEmbeddings(
          "news-backward-fast", has_decoder=True
      ).lm
  
      grammatical = "The company made a profit"
      perplexity_gramamtical_sentence = (
          language_model.calculate_perplexity(grammatical)
      )
  
      ungrammatical = "Nook negh qapla!"
      perplexity_ungramamtical_sentence = (
          language_model.calculate_perplexity(ungrammatical)
      )
  
      print(
          f'"{grammatical}" - perplexity is {perplexity_gramamtical_sentence}'
      )
      print(
          f'"{ungrammatical}" - perplexity is {perplexity_ungramamtical_sentence}'
      )
  
      assert (
          perplexity_gramamtical_sentence
          < perplexity_ungramamtical_sentence
      )
      del language_model
  
file_path: flair/tests/test_language_model.py
imports: import pytest
  from flair.data import Dictionary, Sentence
  from flair.embeddings import FlairEmbeddings, TokenEmbeddings
  from flair.models import LanguageModel
  from flair.trainers.language_model_trainer import LanguageModelTrainer, TextCorpus
label_desc: Use image node_id 4 for calling a global function with example usage: test_compute_perplexity() without return types