Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for classifying objects and returning indices #907

Merged
merged 9 commits into from
Apr 17, 2024
Merged

Conversation

jlowin
Copy link
Member

@jlowin jlowin commented Apr 7, 2024

result = marvin.classify('book', ['a thing you read', 'a thing you sing'], return_index=True)
assert result == 0

Above is a simple example but this is useful when you want to classify objects that aren't already strings. Getting the index makes it easy to match the object to the selected string description

In testing the above, I discovered and fixed (arguably) a bug that cleans up this DX even more. You can now pass objects as labels and get the object back (assuming it can automatically be turned into a string by Pydantic). Previously they would be converted into (bad) string representations, which were returned as the result of the classifier.

class Person(BaseModel):
    name: str
    age: int

p1 = Person(name="Alice", age=30)
p2 = Person(name="Bob", age=25)
p3 = Person(name="Charlie", age=35)

result = marvin.classify("a person in wonderland", [p1, p2, p3])
assert result is p1

@jlowin jlowin changed the title Add support for returning the index of classified labels Add support for returning the index of classified labels and objects Apr 7, 2024
@jlowin jlowin changed the title Add support for returning the index of classified labels and objects Add support for classifying objects and returning indices Apr 7, 2024
Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting!

docs/docs/text/classification.md Outdated Show resolved Hide resolved
@jlowin jlowin merged commit f1500a0 into main Apr 17, 2024
14 of 15 checks passed
@jlowin jlowin deleted the return-index branch April 17, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants