code: def parse_1m_ratings_data(
      dir_path: str,
  ) -> Iterator[Tuple[int, Dict[str, Any]]]:
      """Parses the 1m ratings data."""
      movie_info_map = {}
      for _, movie_example in parse_1m_movies_data(dir_path):
          movie_info_map[movie_example["movie_id"]] = movie_example
  
      users_file_path = os.path.join(dir_path, "users.dat")
      # A list for converting occupation index to occupation string for 1M
      # dataset.
      occupation_index_to_label = [
          "other/not specified",
          "academic/educator",
          "artist",
          "clerical/admin",
          "college/grad student",
          "customer service",
          "doctor/health care",
          "executive/managerial",
          "farmer",
          "homemaker",
          "K-12 student",
          "lawyer",
          "programmer",
          "retired",
          "sales/marketing",
          "scientist",
          "self-employed",
          "technician/engineer",
          "tradesman/craftsman",
          "unemployed",
          "writer",
      ]
      user_info_map = {}
      with tf.io.gfile.GFile(users_file_path, mode="rb") as users_file:
          for line in users_file:
              line = codecs.decode(line, encoding="ISO-8859-1").strip()
              (
                  user_id,
                  gender_str,
                  age,
                  occupation_index,
                  zip_code,
              ) = line.split("::")
              occupation_str = occupation_index_to_label[
                  int(occupation_index)
              ]
              # Combine "K-12 student" and "college/grad student" labels.
              if occupation_str in [
                  "K-12 student",
                  "college/grad student",
              ]:
                  occupation_label = "student"
              else:
                  occupation_label = occupation_str
              user_info_map[user_id] = {
                  "user_gender": gender_str == "M",
                  "bucketized_user_age": age,
                  "user_occupation_label": occupation_label,
                  "user_occupation_text": occupation_str,
                  "user_zip_code": zip_code,
              }
  
      ratings_file_path = os.path.join(dir_path, "ratings.dat")
      with tf.io.gfile.GFile(
          ratings_file_path, mode="rb"
      ) as ratings_file:
          for row_num, line in enumerate(ratings_file):
              line = codecs.decode(line, encoding="ISO-8859-1").strip()
              user_id, movie_id, rating, timestamp = line.split("::")
              movie_info = movie_info_map[movie_id]
              user_info = user_info_map[user_id]
              ex = {
                  "user_id": user_id,
                  "user_rating": rating,
                  "timestamp": timestamp,
              }
              ex.update(movie_info)
              ex.update(user_info)
              yield row_num, ex
  
file_path: datasets/tensorflow_datasets/structured/movielens_parsing.py
imports: import codecs
  import csv
  import os
  from typing import Any, Dict, Iterator, Tuple
  from etils import epath
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 4 for calling a global function with example usage: parse_1m_ratings_data(dir_path) without return types