code: def generate_embeddings(
      data_path,
      news_words,
      news_entities,
      train_entities,
      valid_entities,
      max_sentence=10,
      word_embedding_dim=100,
  ):
      """Generate embeddings.
  
      Args:
          data_path (str): Data path.
          news_words (dict): News word dictionary.
          news_entities (dict): News entity dictionary.
          train_entities (str): Train entity file.
          valid_entities (str): Validation entity file.
          max_sentence (int): Max sentence size.
          word_embedding_dim (int): Word embedding dimension.
  
      Returns:
          str, str, str: File paths to news, word and entity embeddings.
      """
      embedding_dimensions = [50, 100, 200, 300]
      if word_embedding_dim not in embedding_dimensions:
          raise ValueError(
              f"Wrong embedding dimension, available options are {embedding_dimensions}"
          )
  
      logger.info("Downloading glove...")
      glove_path = download_and_extract_glove(data_path)
  
      word_set = set()
      word_embedding_dict = {}
      entity_embedding_dict = {}
  
      logger.info(
          f"Loading glove with embedding dimension {word_embedding_dim}..."
      )
      glove_file = "glove.6B." + str(word_embedding_dim) + "d.txt"
      fp_pretrain_vec = open(
          os.path.join(glove_path, glove_file), "r", encoding="utf-8"
      )
      for line in fp_pretrain_vec:
          linesplit = line.split(" ")
          word_set.add(linesplit[0])
          word_embedding_dict[linesplit[0]] = np.asarray(
              list(map(float, linesplit[1:]))
          )
      fp_pretrain_vec.close()
  
      logger.info("Reading train entities...")
      fp_entity_vec_train = open(train_entities, "r", encoding="utf-8")
      for line in fp_entity_vec_train:
          linesplit = line.split()
          entity_embedding_dict[linesplit[0]] = np.asarray(
              list(map(float, linesplit[1:]))
          )
      fp_entity_vec_train.close()
  
      logger.info("Reading valid entities...")
      fp_entity_vec_valid = open(valid_entities, "r", encoding="utf-8")
      for line in fp_entity_vec_valid:
          linesplit = line.split()
          entity_embedding_dict[linesplit[0]] = np.asarray(
              list(map(float, linesplit[1:]))
          )
      fp_entity_vec_valid.close()
  
      logger.info("Generating word and entity indexes...")
      word_dict = {}
      word_index = 1
      news_word_string_dict = {}
      news_entity_string_dict = {}
      entity2index = {}
      entity_index = 1
      for doc_id in news_words:
          news_word_string_dict[doc_id] = [
              0 for n in range(max_sentence)
          ]
          news_entity_string_dict[doc_id] = [
              0 for n in range(max_sentence)
          ]
          surfaceform_entityids = news_entities[doc_id]
          for item in surfaceform_entityids:
              if (
                  item[1] not in entity2index
                  and item[1] in entity_embedding_dict
              ):
                  entity2index[item[1]] = entity_index
                  entity_index = entity_index + 1
          for i in range(len(news_words[doc_id])):
              if news_words[doc_id][i] in word_embedding_dict:
                  if news_words[doc_id][i] not in word_dict:
                      word_dict[news_words[doc_id][i]] = word_index
                      word_index = word_index + 1
                      news_word_string_dict[doc_id][i] = word_dict[
                          news_words[doc_id][i]
                      ]
                  else:
                      news_word_string_dict[doc_id][i] = word_dict[
                          news_words[doc_id][i]
                      ]
                  for item in surfaceform_entityids:
                      for surface in item[0]:
                          for surface_word in surface.split(" "):
                              if (
                                  news_words[doc_id][i]
                                  == surface_word.lower()
                              ):
                                  if item[1] in entity_embedding_dict:
                                      news_entity_string_dict[doc_id][
                                          i
                                      ] = entity2index[item[1]]
              if i == max_sentence - 1:
                  break
  
      logger.info("Generating word embeddings...")
      word_embeddings = np.zeros([word_index, word_embedding_dim])
      for word in word_dict:
          word_embeddings[word_dict[word]] = word_embedding_dict[word]
  
      logger.info("Generating entity embeddings...")
      entity_embeddings = np.zeros([entity_index, word_embedding_dim])
      for entity in entity2index:
          entity_embeddings[
              entity2index[entity]
          ] = entity_embedding_dict[entity]
  
      news_feature_path = os.path.join(data_path, "doc_feature.txt")
      logger.info(
          f"Saving word and entity features in {news_feature_path}"
      )
      fp_doc_string = open(news_feature_path, "w", encoding="utf-8")
      for doc_id in news_word_string_dict:
          fp_doc_string.write(
              doc_id
              + " "
              + ",".join(list(map(str, news_word_string_dict[doc_id])))
              + " "
              + ",".join(
                  list(map(str, news_entity_string_dict[doc_id]))
              )
              + "\n"
          )
  
      word_embeddings_path = os.path.join(
          data_path,
          "word_embeddings_5w_" + str(word_embedding_dim) + ".npy",
      )
      logger.info(f"Saving word embeddings in {word_embeddings_path}")
      np.save(word_embeddings_path, word_embeddings)
  
      entity_embeddings_path = os.path.join(
          data_path,
          "entity_embeddings_5w_" + str(word_embedding_dim) + ".npy",
      )
      logger.info(f"Saving word embeddings in {entity_embeddings_path}")
      np.save(entity_embeddings_path, entity_embeddings)
  
      return (
          news_feature_path,
          word_embeddings_path,
          entity_embeddings_path,
      )
  
imports: import os
  import random
  import logging
  import json
  import numpy
  import re
  from tqdm import tqdm
  from nltk.tokenize import RegexpTokenizer
  from recommenders.datasets.download_utils import maybe_download, download_path, unzip_file
label_desc: Use image node_id 11 for calling a global function with example usage: generate_embeddings(data_path, news_words, news_entities, train_entities, valid_entities, max_sentence, word_embedding_dim) and returns: news_feature_path,  word_embeddings_path,  entity_embeddings_path