Skip to content

Commit

Permalink
Add chunking example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasgarbas committed Nov 11, 2024
1 parent 2f57f28 commit bc2eb98
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/code_examples/chunking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from datasets import load_dataset
from transformer_ranker import TransformerRanker

# Load the 'conll2003' dataset
dataset = load_dataset('conll2003')

# Use smaller models to test on CPU
models = ['prajjwal1/bert-tiny',
'google/electra-small-discriminator',
'microsoft/deberta-v3-small',
'bert-base-uncased',
]

# Initialize the ranker, set labels to chunk tags
ranker = TransformerRanker(dataset=dataset,
dataset_downsample=0.2,
label_column='chunk_tags')

# ... and run it
result = ranker.run(models=models, batch_size=64)

# Print the scores
print(result)

"""Result
Rank 1. microsoft/deberta-v3-small: 4.398
Rank 2. bert-base-uncased: 4.149
Rank 3. google/electra-small-discriminator: 3.7423
Rank 4. prajjwal1/bert-tiny: 2.9444
"""

0 comments on commit bc2eb98

Please sign in to comment.