code: def merge_label_to_id_mappings(
      left: TriplesFactory,
      right: TriplesFactory,
      relation_offsets: torch.LongTensor,
      # optional
      entity_offsets: Optional[torch.LongTensor] = None,
      entity_mappings: Optional[Sequence[Mapping[int, int]]] = None,
      extra_relations: Optional[Mapping[str, int]] = None,
  ) -> Tuple[Mapping[str, int], Mapping[str, int]]:
      """
      Merge entity-to-id and relation-to-id mappings.
  
      :param left:
          the left triples factory
      :param right:
          the right triples factory
      :param relation_offsets: shape: (2,)
          the relation offsets
      :param entity_offsets: shape: (2,)
          the entity offsets, if entities are shifted uniformly
      :param entity_mappings:
          explicit entity ID remappings
      :param extra_relations:
          additional relations, as a mapping from their label to IDs
  
      :return:
          the updated entity and relation to id mappings
      """
      # merge entity mapping
      entity_to_id = merge_label_to_id_mapping(
          (EA_SIDE_LEFT, left.entity_to_id),
          (EA_SIDE_RIGHT, right.entity_to_id),
          offsets=entity_offsets,
          mappings=entity_mappings,
      )
      # merge relation mapping
      relation_to_id = merge_label_to_id_mapping(
          (EA_SIDE_LEFT, left.relation_to_id),
          (EA_SIDE_RIGHT, right.relation_to_id),
          offsets=relation_offsets,
          extra=extra_relations,
      )
      return entity_to_id, relation_to_id
  
imports: import logging
  from abc import ABC, abstractmethod
  from collections import defaultdict
  from typing import Any, ClassVar, DefaultDict, Dict, Iterable, Mapping, NamedTuple, Optional, Sequence, Set, Tuple, Union
  import numpy
  import pandas
  import torch
  from class_resolver import ClassResolver
  from pandas.api.types import is_numeric_dtype, is_string_dtype
  from ...triples import CoreTriplesFactory, TriplesFactory
  from ...typing import COLUMN_HEAD, COLUMN_TAIL, EA_SIDE_LEFT, EA_SIDE_RIGHT, EA_SIDES, MappedTriples, TargetColumn
  from ...utils import format_relative_comparison, get_connected_components
label_desc: Use image node_id 3 for calling a global function with example usage: merge_label_to_id_mappings(left, right, relation_offsets, entity_offsets, entity_mappings, extra_relations) and returns: entity_to_id,  relation_to_id