Skip to content

Commit

Permalink
Merge pull request #905 from PrefectHQ/update-docs-title
Browse files Browse the repository at this point in the history
Update classification.md
  • Loading branch information
jlowin authored Apr 7, 2024
2 parents 5a5cd1d + 4c63e04 commit dfa3136
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions docs/docs/text/classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
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.

0 comments on commit dfa3136

Please sign in to comment.