Looking for the format of the dataset:

#2
by Dogebooch - opened

Are there train and test spits on this dataset, and is there a format were the tags column is the label_ID's rather than the labels themselves? I'm having some trouble changing the dataset into a similar format as other NER datasets like: ncbi_disease etc

The format is created to be compatible with Huggingface AutoModelForTokenClassification. I didn't create any other format. You can find my example training notebook here:
https://colab.research.google.com/drive/1OzCY782KJSF0FBDS0d1CoMhfp3-RtJMV?usp=sharing

Ah thanks so much i'll play around with it a little.

from datasets import load_dataset
import numpy as np

#But then after that it's back to normal
try:
    # Try to get the feature names directly
    feature_names = MACCROBAT['train'].features['tags'].feature.names
except AttributeError:
    # If 'feature.names' is not available, get the unique tags as before
    all_tags = np.concatenate(MACCROBAT['train']['tags'])
    unique_labels = np.unique(all_tags)
    feature_names = sorted(unique_labels)

# Print sorted labels
print(MACCROBAT)
for i, name in enumerate(feature_names):
    print(f"{i}: {name}")
MACCROBAT_original_labels = {
    0: "B-Activity",
    1: "B-Administration",
    2: "B-Age",
    3: "B-Area",
    4: "B-Biological_attribute",
    5: "B-Biological_structure",
    6: "B-Clinical_event",
    7: "B-Color",
    8: "B-Coreference",
    9: "B-Date",
    10: "B-Detailed_description",
    11: "B-Diagnostic_procedure",
    12: "B-Disease_disorder",
    13: "B-Distance",
    14: "B-Dosage",
    15: "B-Duration",
    16: "B-Family_history",
    17: "B-Frequency",
    18: "B-Height",
    19: "B-History",
    20: "B-Lab_value",
    21: "B-Mass",
    22: "B-Medication",
    23: "B-Nonbiological_location",
    24: "B-Occupation",
    25: "B-Other_entity",
    26: "B-Other_event",
    27: "B-Outcome",
    28: "B-Personal_background",
    29: "B-Qualitative_concept",
    30: "B-Quantitative_concept",
    31: "B-Severity",
    32: "B-Sex",
    33: "B-Shape",
    34: "B-Sign_symptom",
    35: "B-Subject",
    36: "B-Texture",
    37: "B-Therapeutic_procedure",
    38: "B-Time",
    39: "B-Volume",
    40: "B-Weight",
    41: "I-Activity",
    42: "I-Administration",
    43: "I-Age",
    44: "I-Area",
    45: "I-Biological_attribute",
    46: "I-Biological_structure",
    47: "I-Clinical_event",
    48: "I-Color",
    49: "I-Coreference",
    50: "I-Date",
    51: "I-Detailed_description",
    52: "I-Diagnostic_procedure",
    53: "I-Disease_disorder",
    54: "I-Distance",
    55: "I-Dosage",
    56: "I-Duration",
    57: "I-Family_history",
    58: "I-Frequency",
    59: "I-Height",
    60: "I-History",
    61: "I-Lab_value",
    62: "I-Mass",
    63: "I-Medication",
    64: "I-Nonbiological_location",
    65: "I-Occupation",
    66: "I-Other_entity",
    67: "I-Other_event",
    68: "I-Outcome",
    69: "I-Personal_background",
    70: "I-Qualitative_concept",
    71: "I-Quantitative_concept",
    72: "I-Severity",
    73: "I-Shape",
    74: "I-Sign_symptom",
    75: "I-Subject",
    76: "I-Texture",
    77: "I-Therapeutic_procedure",
    78: "I-Time",
    79: "I-Volume",
    80: "I-Weight",
    81: "O",
}

from sklearn.model_selection import train_test_split

# Assume that 'dataset' is a list of dictionaries with 'tokens' and 'tags'
tokens = [example['tokens'] for example in MACCROBAT]
tags = [example['tags'] for example in MACCROBAT]

# Split the dataset into training and testing sets
tokens_train, tokens_test, tags_train, tags_test = train_test_split(tokens, tags, test_size=0.2, random_state=42)

# Convert the split data back into the original format
train_data = [{'tokens': tok, 'tags': tag} for tok, tag in zip(tokens_train, tags_train)]
test_data = [{'tokens': tok, 'tags': tag} for tok, tag in zip(tokens_test, tags_test)]

# Create a dictionary with the split datasets
MACCROBAT = {'train': train_data, 'test': test_data}

This is kind of what I was trying to do, so I can make it a similar format with the others so I can combine them, but I think the problem is that the tokenizer is reading the str label, not the Label_ID. Idk if you have any quick fixes, but I appreciate the reply from earlier I'll check it out.

Thanks again
-Doug

Hi in the original dataset each sample is a text, but here its a list of tokens. How did you split the text into tokens and align the labels? Can you share the code that transformed the original data to this format?
Thanks

Sign up or log in to comment