Skip to content

Log text¶

Comet allows you to log any text to your Experiment, where a text is defined as any variable-length string.

Example of Text tab
Example of text rendered in the Comet UI

Comet allows you to analyze experiment assets by loading them into Python Panels with custom code.

The following method can be used to log text samples:

In addition all the text samples logged to an Experiment can be view in the Single Experiment page tabs:

For example, you could...

Log text samples either at the end of a training run or during the run when training or fine-tuning an NLP model.
But keep in mind that you want to use CometLLM for prompt engineering workflows!

Log a text with metadata¶

The example below logs a single sentence representing a movie review with metadata defining the review sentiment.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import comet_ml

# Initialize the Comet Experiment
comet_ml.login()
exp = comet_ml.start()

# Create an example text sentence with associated metadata
sentence = "This movie was amazing! I loved every minute of it."
metadata = {"sentiment": "Positive"}

# Log the example text to Comet
exp.log_text(text=sentence,  metadata=metadata)

The metadata argument requires a JSON-encodable dictionary of any custom key<>value pairs. Additionally, you can pass the step argument to associate the text to a training step.

Nov. 18, 2024