From d1de84a2cc4a8b1e0f2e0585cd13e380e135faf2 Mon Sep 17 00:00:00 2001 From: Julian Risch Date: Fri, 1 Oct 2021 12:24:44 +0200 Subject: [PATCH] Create classifier.mdx --- docs/latest/components/classifier.mdx | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docs/latest/components/classifier.mdx diff --git a/docs/latest/components/classifier.mdx b/docs/latest/components/classifier.mdx new file mode 100644 index 000000000..223a33178 --- /dev/null +++ b/docs/latest/components/classifier.mdx @@ -0,0 +1,43 @@ +# Classifier + +The Classifier Node is a transformer based classification model used to create predictions that can be attached to retrieved documents as metadata. +For example, by using a sentiment model, you can label each document as being either positive or negative in sentiment. +Through a tight integration with the HuggingFace model hub, you can easily load any classification model by simply supplying the model name. + +![image](/img/classifier.png) + +
+ +Note that the Classifier is different from the Query Classifier. +While the Query Classifier categorizes incoming queries in order to route them to different parts of the pipeline, +the Classifier is used to create classification labels that can be attached to retrieved documents as metadata. + +
+ +## Usage + +Initialize it as follows: + +``` python +from haystack.classifier import FARMClassifier + +classifier_model = 'textattack/bert-base-uncased-imdb' +classifier = FARMClassifier(model_name_or_path=classifier_model) +``` + +It slotted into a pipeline as follows: + +``` python +pipeline = Pipeline() +pipeline.add_node(component=retriever, name="Retriever", inputs=["Query"]) +pipeline.add_node(component=classifier, name='Classifier', inputs=['Retriever']) +``` + +It can also be run in isolation: + +``` python +documents = classifier.predict( + query="", + documents = [doc1, doc2, doc3, ...] +): +```