Skip to main content

INSPIRE package aimed to automatically classify the new papers that are added to INSPIRE, such as if they are core or not.

Project description

Inspire Classifier

About

INSPIRE package aimed to automatically classify the new papers that are added to INSPIRE, such as if they are core or not.

The current implementation uses the ULMfit approach. Universal Language Model Fine-tuning, is a method for training text classifiers by first pre-training a language model on a large corpus to learn general language features (in this case a pre-loaded model, which was trained using the WikiText-103 dataset is used). The pre-trained model is then fine-tuned on the title and abstract of the INSPIRE dataset before training the classifier on top.

Package Usage

from inspire_classifier import Classifier

classifier = Classifier(model_path="PATH/TO/MODEL.h5")

title = "Search for new physics in high-energy particle collisions"
abstract = "We present results from a search for beyond..."

result = classifier.predict_coreness(title, abstract)
print(result) --> {'prediction': 'core', 'scores': {'rejected': 0.1, 'non_core': 0.3, 'core': 0.6}}

Installation for local usage and Training:

  • Install and activate python 3.11 environment (for example using pyenv)
  • Install poetry: pip install poetry==1.8.3
  • Run poetry install: poetry install

Train new classifier model

1. Gather training data

Set the environment variables for inspire-prod es database and run the create_dataset.py file, passing the range of years. This will create a inspire_classifier_dataset.pkl, containing the label (core, non-core, rejected) as well as the title and abstract of the fetched records. This data will be used in the next step to train the model. Make sure the generated file is called inspire_classifier_dataset.pkl!

export ES_USERNAME=XXXX
export ES_PASSWORD=XXXX

poetry run python scripts/create_dataset.py --year-from $YEAR_FROM --month-from $MONTH_FROM --year-to $YEAR_TO --month-to $MONTH_TO

($MONTH_FROM and $MONTH_TO are optional parameters)

2. Run training and validate model

The train_classifier.py script will run the commands to train and validate a new model. Configurations changes like the amount of training epochs as well as the train-test split can be adjusted here. In short, the script first splits the pkl file from the first step into a training and a test dataset inside the classifier/data folder. The training set is then used to train the model, while the test set is used to evaluate the model after the training is finished. The model will be saved into classifier/models/language_model/finetuned_language_model_encoder.h5

poetry run python scripts/train_classifier.py

3. Upload the model to CERN S3

In order to use the new model in production upload it to CERN S3 and follow this writeup

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inspire_classifier-2.0.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inspire_classifier-2.0.5-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file inspire_classifier-2.0.5.tar.gz.

File metadata

  • Download URL: inspire_classifier-2.0.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inspire_classifier-2.0.5.tar.gz
Algorithm Hash digest
SHA256 2e10b160b3e9db54c0e14124074fced2c777bdad1d81a7fd45964c5ee0eae21a
MD5 64db65100a6e09df24b05b69f6940457
BLAKE2b-256 b339cd5baa1c1b77810c95e122f55c45d47aac99f1fde1ecc022fd1ffc2ce146

See more details on using hashes here.

File details

Details for the file inspire_classifier-2.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for inspire_classifier-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d4013e3a7019b8b55ef59ad0f81474e4285af8dd3407076017b9338a42081dbd
MD5 184e494f469b16eddd30b8122fbb0b60
BLAKE2b-256 10ae1293fa3cc868a910640f5315a4681deb68ff2fd387965eb4f56ec4c7b77a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page