code: def collect_entities_by_type(
      relation_types: Dictionary,
      entity_configs: Dict[str, EntitySchema],
      relation_configs: List[RelationSchema],
      edge_paths: List[Path],
      dynamic_relations: bool,
      edgelist_reader: EdgelistReader,
      entity_min_count: int,
  ) -> Dict[str, Dictionary]:
      counters: Dict[str, Counter[str]] = {}
      for entity_name in entity_configs.keys():
          counters[entity_name] = Counter()
  
      log("Searching for the entities in the edge files...")
      for edgepath in edge_paths:
          for (
              lhs_word,
              rhs_word,
              rel_word,
              _weight,
          ) in edgelist_reader.read(edgepath):
              if dynamic_relations or rel_word is None:
                  rel_id = 0
              else:
                  try:
                      rel_id = relation_types.get_id(rel_word)
                  except KeyError:
                      raise RuntimeError(
                          "Could not find relation type in config"
                      )
  
              counters[relation_configs[rel_id].lhs][lhs_word] += 1
              counters[relation_configs[rel_id].rhs][rhs_word] += 1
  
      entities_by_type: Dict[str, Dictionary] = {}
      for entity_name, counter in counters.items():
          log(f"Entity type {entity_name}:")
          log(f"- Found {len(counter)} entities")
          if entity_min_count > 0:
              log(
                  f"- Removing the ones with fewer than {entity_min_count} occurrences..."
              )
              counter = Counter(
                  {
                      k: c
                      for k, c in counter.items()
                      if c >= entity_min_count
                  }
              )
              log(f"- Left with {len(counter)} entities")
          log("- Shuffling them...")
          names = list(counter.keys())
          random.shuffle(names)
          entities_by_type[entity_name] = Dictionary(
              names,
              num_parts=entity_configs[entity_name].num_partitions,
          )
  
      return entities_by_type
  
imports: import datetime
  import random
  from abc import ABC, abstractmethod
  from contextlib import ExitStack
  from pathlib import Path
  from typing import Any, Counter, Dict, Iterable, List, Optional, Tuple
  import torch
  from torchbiggraph.config import EntitySchema, RelationSchema
  from torchbiggraph.converters.dictionary import Dictionary
  from torchbiggraph.edgelist import EdgeList
  from torchbiggraph.entitylist import EntityList
  from torchbiggraph.graph_storages import AbstractEdgeAppender, AbstractEdgeStorage, AbstractEntityStorage, AbstractRelationTypeStorage, EDGE_STORAGES, ENTITY_STORAGES, RELATION_TYPE_STORAGES
  from torchbiggraph.types import UNPARTITIONED
label_desc: Use image node_id 3 for calling a global function with example usage: collect_entities_by_type(relation_types, entity_configs, relation_configs, edge_paths, dynamic_relations, edgelist_reader, entity_min_count) and returns: entities_by_type