Skip to main content

ClassiVax

Classify vaccine-related news headlines into topic categories using a Recognizing Textual Entailment (RTE) approach, powered by the LuizNeves/BERT-NLI-vaccine-v2 model.

Built on the method described in:

Neves, L. F. F., Camargo, C. Q., & Massarani, L. (2025). Boosting Transformers: Recognizing Textual Entailment for Classification of Vaccine News Coverage. Computational Communication Research, 7(1), 1–32. https://doi.org/10.5117/CCR2025.1.1.NEVE

Installation

pip install classivax

Usage

from classivax import ClassiVaxClassifier

clf = ClassiVaxClassifier()

result = clf.classify("Twitter will begin removing vaccine misinformation")
print(result["class"])   # "Vaccine Hesitancy and Mis-/Disinformation"
print(result["score"])   # e.g. 0.999

Note: if the text does not clearly match any of the provided classes (i.e., none of them achieve the entailment label), result["class"] and result["score"] will be None. Always check for this case rather than assuming a class is always returned:

result = clf.classify("some unrelated text")
if result["class"] is None:
    print("No class matched this text.")
else:
    print(result["class"], result["score"])

Batch classification

headlines = [
    "Twitter will begin removing vaccine misinformation",
    "Britain begins coronavirus vaccine rollout",
    "COVID-19 vaccination key to economic recovery",
]

df = clf.classify_batch(headlines)
print(df)

Custom classes

The underlying RTE approach also supports classifying text against any set of natural-language class descriptions you define — not just the original 10 classes.

custom_classes = {
    "Vaccine Safety Debate": "The headline discusses concerns, controversies, or debates about vaccine safety",
    "Vaccine Logistics": "The headline discusses shipping, storage, cold chain, or distribution logistics for vaccines",
}

clf = ClassiVaxClassifier(classes=custom_classes)
result = clf.classify("Cold storage shortages delay vaccine shipments to rural areas")
print(result["class"])  # "Vaccine Logistics"

Note: the underlying model was fine-tuned specifically on English-language, vaccine-related headlines from 2020–2021. Using custom classes outside this domain is supported, but accuracy has not been formally evaluated beyond the original study's scope — treat results on very different domains with appropriate caution.

The 10 default classes

Class Description
Global Access to Vaccine Initiatives for equal access to COVID-19 vaccines (e.g., COVAX), and/or the need to combat inequity, ensure global distribution, and contain the disease, especially in low- and middle-income countries
Science and Technology The science behind vaccine development, including research, studies, safety and efficacy trials, emergency approval, and side effects
Public Health Policies Vaccine mandates, vaccine passports, and/or other public health policies such as social distancing, quarantine, lockdowns, and mask mandates
Vaccination Rollout/Campaign Vaccination rollout, campaigns, priority groups, vaccine deals, and/or the monitoring of vaccination rates
Vaccine Hesitancy and Mis-/Disinformation The circulation of disinformation and misinformation regarding vaccines, which contribute to vaccine hesitancy and reluctance
Public Endorsement to Vaccine Public endorsement and incentive for vaccines, such as celebrities and artists getting vaccinated
Institutional Affairs Institutional and governmental issues, political disputes, conflicts, political authorities, and export bans
Problems in Vaccination Problems in vaccination, such as delays, fraud, disparities, vaccine shortages
Public Perception of Vaccine Opinion polls and surveys on the public perception of vaccines and/or willingness to get vaccinated
Economic Consequences The impacts and benefits of vaccination on the economy

How it works

For each headline, the classifier tests it against every class description as a text-hypothesis pair, following the entailment framework: the headline is the text (T), and each class description is a candidate hypothesis (H). The class whose description achieves the highest entailment score is selected as the prediction.

Troubleshooting

ImportError: cannot import name 'pipeline' from 'transformers'

If you see this error, especially in an Anaconda environment, it is usually not actually about transformers — it is caused by outdated or mismatched versions of Pillow and/or torchvision already installed in that environment, which transformers imports internally even for text-only tasks like this one.

To check, run:

import transformers
transformers.pipeline

and read the full traceback (not just the last line). Common underlying errors:

  • AttributeError: module 'PIL.Image' has no attribute 'Resampling' → your Pillow is too old. Fix with:
    pip install --upgrade Pillow
    
  • AttributeError: NEAREST_EXACT (or a similar torchvision.transforms.InterpolationMode error) → your torchvision is out of sync with transformers/torch. Since classivax only performs text classification, the simplest fix is to remove torchvision entirely:
    pip uninstall torchvision -y
    
    transformers will detect that torchvision is unavailable and skip the image-processing code path that causes the conflict.

After either fix, restart your Python kernel/interpreter before importing classivax again — a partially-loaded transformers module will not resolve itself without a restart.

Jupyter notebook can't find the package after pip install classivax

If you installed classivax inside a virtual environment but your notebook still fails to import it, your notebook is likely running a different Python kernel (e.g., a base Anaconda installation) than the one where you ran pip install. Register your environment as a Jupyter kernel:

pip install ipykernel
python -m ipykernel install --user --name=myenv --display-name "Python (myenv)"

Then, in Jupyter, go to Kernel → Change kernel and select the newly registered environment.

Citation

If you use this library or the underlying model in your research, please cite:

@article{neves2025boosting,
  title={Boosting Transformers: Recognizing Textual Entailment for Classification of Vaccine News Coverage},
  author={Neves, Luiz F. F. and Camargo, Chico Q. and Massarani, Luisa},
  journal={Computational Communication Research},
  volume={7},
  number={1},
  pages={1--32},
  year={2025},
  doi={10.5117/CCR2025.1.1.NEVE}
}

License

MIT

Metadata

Release files for classivax 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for classivax 0.1.1
File Size Uploaded
classivax-0.1.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for classivax 0.1.1
File Interpreter ABI Platform
classivax-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / classivax-0.1.1.tar.gz

Download URL classivax-0.1.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4fd6bec9e7fb017f4445f5f97e0b9b9748869fd7a6ec41390e74f5864208365c
BLAKE2b-256 checksum
How to use checksums
fb2be0147198980987351a39f9bc65182bd0512919380bea7762dd1a2ed4085d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.8

Release files / classivax-0.1.1-py3-none-any.whl

Download URL classivax-0.1.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
212e10629af674f22ad80a7490927f7980c1a8c1ee13a564348c20618b8ed4cd
BLAKE2b-256 checksum
How to use checksums
4be9fe9f1f7b0f7f415bd4b7a64ea17376cc39592e7bfe972047b339e1b078cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page