To achieve your goal, you would typically use the Hugging Face datasets library to load your dataset and then analyze the conversation field according to your criteria (counting empty turns and conversations containing empty user turns).
Here is an example code snippet to guide you through this process:
from datasets import load_dataset
# Load the dataset
dataset = load_dataset("yuntian-deng/WildChat-1M-internal")
# Initialize counters
total_empty_turns = 0
total_turns = 0
conversations_with_empty_user_turns = 0
# Iterate through the dataset
for conversation in dataset['train']:
has_empty_user_turn = False # Flag to check if the current conversation contains an empty user turn
for turn in conversation['conversation']:
total_turns += 1
if turn['content'] == "":
total_empty_turns += 1
if turn['role'] == "user":
has_empty_user_turn = True
if has_empty_user_turn:
conversations_with_empty_user_turns += 1
print(f"Total empty turns: {total_empty_turns} out of {total_turns} total turns.")
print(f"Conversations with at least one empty user turn: {conversations_with_empty_user_turns}")
Please, adjust the dataset access key ['train'] according to how your dataset is structured (for instance, if it is split into 'train', 'validation', 'test', etc., or if it's a single dataset without splits).
This script does the following:
- Load the Dataset: It uses
load_dataset to fetch the specified dataset.
- Iterate Through Conversations and Turns: It goes through each conversation and each turn within each conversation.
- Check for Empty Content: During iteration, it checks if the
content field is an empty string. If an empty turn is found, it increments the total_empty_turns counter.
- Flag Empty User Turns: It also checks if any turn with an empty
content belongs to a "user". If found, it sets a flag indicating this conversation contains at least one empty user turn.
- Count Conversations With Empty User Turns: If a conversation has at least one user turn with empty content, it increments the
conversations_with_empty_user_turns counter.
- Print Results: Finally, it prints out the count of total empty turns and how many conversations contain at least one empty user turn.
Make sure to install the datasets library from Hugging Face before running this script. You can install it using pip:
pip install datasets
Adjust any specifics as per your dataset structure or requirements.