Package: op-text
OP TextA wrapper around the populartransformersmachine learning library, by the HuggingFace team. OP Text provides a simplified,Keraslike, interface for fine-tuning, evaluating and inference of popular pretrained BERT models.InstallationPyTorch is required as a prerequisite before installing OP Text. Head on over to thegetting started  pageof their website and follow the installation instructions for your version of Python.!Currently only Python versions 3.6 and above are supportedUse one of the following commands to install OP Text:with pippip install op_textwith anacondaconda install op_textUsageThe entire purpose of this package is to allow users to leverage the power of the transformer models available in HuggingFace's library without needing to understand how to use PyTorch.Model LoadingCurrently the available models are:BERTfrom the paperBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding(https://arxiv.org/abs/1810.04805)released by Google.RoBERTafrom the paperRobustly Optimized BERT Pretraining Approachreleased by Facebook.DistilBERTfrom the paperDistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighterreleased by HuggingFace.Each model has contains a list of the available pretrained models.
Use theDOWNLOADABLESproperty to access them.Bert.DOWNLOADBLES
>> ['bert-base-uncased','bert-large-uncased']

Roberta.DOWNLOADBLES
>> ['roberta-base','roberta-large']

DistilBert.DOWNLOADABLES
>> ['distilbert-base-uncased']Loading a model is achieved in one line of code. The string can either be the name of a pretrained model or a path to a local fine-tuned model on disk.from op_text.models import Bert

# Loading a pretrained model 
model = Bert("bert-base-uncased", num_labels=2)

# Loading a fine-tuned model
model = Bert("path/to/local/model/")Supplynum_labelswhen using a pretrained model, as an untrained classification head is added when using this one of the DOWNLOADABLE strings.Fine-tuningFinetuning a model is as simple as loading a dataset, instantiating a model and then passing it to the modelsfitfunction.from models.import Bert

X_train = [
	"Example sentence 1"
	"Example sentence 2"
	"Today was a horrible day"
]
y_train = [1,1,0]

model = Bert('bert-base-uncased', num_labels=2)
model.fit(X_train, y_train)SavingAt the conclusion of training you will most likely want to save your model to disk. Simply call the the modelssavefunction and supply an output directory and name for the model.from models.import Bert
model = Bert('bert-base-uncased', num_labels=2)
model.save("path/to/output/dir/", "example_save_name")EvaluationModel evaluation is basically the same as model training. Load a dataset, instantiate a model and but instead call theevaluatefunction. This returns a number between 0 and 1 which is the percentage of predictions the model got correct.model.evalaute(X_test, y_test)
>> 0.8 # 80% correct predictionsPredictionPredict the label of a piece of text/s by passing a list of strings to the modelspredictfunction.  This returns a list of tuples, one for each piece of text to be predicted. These tuples contain the models confidence scores for each class and the numerical label of the predicted class. If a label converter is supplied, a string label of the predicted class is also included in each output tuple.from op_text.utils import LabelConverter

converter = LabelConverter({0: "negative", 1: "positive"}    
to_predict = ["Today was a great day!"]
model.predict(to_predict, label_converter=converter)
>> [([0.02, 0.98], 1, "positive")]CitationPaper you can cite for the  Transformers library:@article{Wolf2019HuggingFacesTS,
  title={HuggingFace's Transformers: State-of-the-art Natural Language Processing},
  author={Thomas Wolf and Lysandre Debut and Victor Sanh and Julien Chaumond and Clement Delangue and Anthony Moi and Pierric Cistac and Tim Rault and R'emi Louf and Morgan Funtowicz and Jamie Brew},
  journal={ArXiv},
  year={2019},
  volume={abs/1910.03771}
}