imperial-science/newspapers_classifier_colonial
Colonial Newspaper Classifier
Model Description
newspapers_classifier_colonial is a fine-tuned roberta-large model that has been trained to identify historical British newspaper articles related to colonial topics. We take the initialized roberta-large weights and fine tune on a custom dataset of local and regional newspaper articles published between 1750-1950.
Usage
This model can be used with HuggingFace Transformer's Pipelines API for text classification:
from transformers import pipeline
classifier = pipeline(
"text-classification",
model='imperial-science/newspapers_classifier_colonial',
device=0,
truncation=True,
max_length=512
)
example = """
BRITISH EAST AFRICA.*,
The centre of our special interest in Africa is continually shifting. One day it is in Egypt, another in Morocco ; one day in Uganda, another in Mashonaland.
No sooner have affairs in the East settled down into a calm of greater or less duration than there is a crisis in the South,
and once more the resources of civilisation are engaged in the task of proving to a savage race the hopelessness of the effort
to maintain the old conditions of primitive barbarism in the face of European progress.
Only a few months ago the public, the Press, and the Parliament were as much occupied with operations in East Africa as they have been during
the last few weeks with the expedition against Lobengula.
Captain Lugard has already, on many occasions, told the story of the Uganda affair in the most straightforward manner,
and tho whole case of the British East Africa Company has been placed before tlie country, so that,
so far as concerns the particular question with which his name is most prominently connected,
all that the reader will find in these two volumes is a more detailed narrative than has yet been published of the
events which led up to and accompanied the lamentable loss of life which attracted so much attention,
events which have been followed by the evacuation of Uganda by the Company and the .Mission of Sir Gerald Portal,
the results of which have yet to be seen.
"""
def classify(article):
"""
Classify text(s) as either 'COLONIAL' or 'NOT'.
Parameters:
article (str or list of str): The text(s) to be classified. Can be a single string
or a list of strings.
Returns:
list of dict: A list of dictionaries, each containing:
- 'label' (str): Either 'COLONIAL' or 'NOT'
- 'score' (float): The confidence score of the classification
"""
if isinstance(article, str):
article = [article]
results = classifier(article)
output = []
for result in results:
label = "COLONIAL" if result["label"] == "LABEL_1" else "NOT"
output.append({'label': label, 'score': result["score"]})
return output
print(classify(example))Training data
The custom dataset consists of 52,749 newspaper articles drawn from Parts I-V of Gale's British Library Newspapers corpus. Articles consist of the article titles (usually capitalized) followed by the article text.
Labels were generated by GPT-4 with the following prompt and a subsample of 10% was checked by a graduate student:
You are an expert in labelling for text classification, trained to analyze newspaper articles published in Britain during 1750-1950.
The newspaper article will have OCR errors.
Your task is to classify a given article based on its focus.
Specifically, you should determine if the article primarily discusses the British Empire, British imperialism, scientific exploration, colonists and settlers, indigenous people, or other colonial topics relating to Britain (including those related to Ireland),
which we'll refer to as 'talking about imperialism'.
Do not provide an explanation. Simply respond in JSON format, so that if the article text is ‘talking about imperialism’, respond with 'response' of ‘yes’. If it is ‘not’, set 'response' to ‘no’.
Here is the article text:We make no attempt to correct for OCR errors in any way beforehand, so that the model is exposed to these errors in training.
Our class balance for the labels was: 7.4% 'yes', and 92.6% 'no'.
The data was randomly split 60-20-20 (train-val-test), and fine tuning was done with a batch size of 165 and learning rate of 2e-5 for 5 epochs. Only the first 128 tokens were passed to the model for classification.
Evaluation
The F1 on the test set was 93.4%.
