INNER CODE UNIT · Python
write_trajectories_to_file
GoogleCloudPlatform/vertex-ai-samples · community-content/tf_agents_bandits_movie_recommendation_with_kfp_and_vertex_sdk/mlops_pipeline_tf_agents_bandits_movie_recommendation/src/logger/main.py:167
def write_trajectories_to_file(
dataset_file: str,
environment: tf_py_environment.TFPyEnvironment,
observations: List[Dict[str, List[List[float]]]],
predicted_actions: List[Dict[str, List[float]]]) -> None:
"""Writes trajectory data to a file, each JSON in one line.
Gets `trajectories.Trajectory` objects that encapsulate environment
feedback eg. rewards based on `observations` and `predicted_actions`.
Each `trajectories.Trajectory` object gets written as one line to
`dataset_file` in JSON format. I.e., the `dataset_file` would be a
newline-delimited JSON file.
Args:
dataset_file: Path to a JSON file containing the training dataset.
environment: A TF-Agents environment that holds observations, apply actions
and returns rewards.
observations: List of `{"observation": <observation>}` in the prediction