diff --git a/docs/docs/text/classification.md b/docs/docs/text/classification.md index 66c9d8961..d44f075bd 100644 --- a/docs/docs/text/classification.md +++ b/docs/docs/text/classification.md @@ -126,26 +126,34 @@ category = marvin.classify( assert category == "usability feedback" ``` -### Details and few-shot examples +### Adding detailed instructions In more complex cases, where the context and specifics are crucial for accurate classification, detailed instructions play a critical role: ```python -# Classifying a task based on project specifications -project_specs = { - "Frontend": "Tasks involving UI design, CSS, and JavaScript.", - "Backend": "Tasks related to server, database, and application logic.", - "DevOps": "Tasks involving deployment, CI/CD, and server maintenance." -} - -task_description = "Set up the server for the new application." - -task_category = marvin.classify( - task_description, - labels=list(project_specs.keys()), - instructions="Match the task to the project category based on the provided specifications." +# Classifying a customer review as positive, negative, or neutral +review_sentiments = [ + "Positive", + "Negative", + "Neutral" +] + +review = "The product worked well, but the delivery took longer than expected." + +# Without instructions +predicted_sentiment = marvin.classify( + review, + labels=review_sentiments +) +assert predicted_sentiment == "Negative" + +# With instructions +predicted_sentiment = marvin.classify( + review, + labels=review_sentiments, + instructions="Focus on the sentiment towards the product itself, rather than the purchase experience." ) -assert task_category == "Backend" +assert predicted_sentiment == "Positive" ``` ## Enums as classifiers @@ -204,4 +212,4 @@ assert result == ["bug", "inquiry"] (`marvin.classify_async.map` is also available for async environments.) -Mapping automatically issues parallel requests to the API, making it a highly efficient way to classify multiple inputs at once. The result is a list of classifications in the same order as the inputs. \ No newline at end of file +Mapping automatically issues parallel requests to the API, making it a highly efficient way to classify multiple inputs at once. The result is a list of classifications in the same order as the inputs.