Hierarchy classification
In some instances it's necessary to classify text data into a hierarchy of categories. The TrueState Python SDK provides a high-level API for making predictions on your hierarchy classification models.
from truestate.inference import hierarchy_classificaiton
sample_text = "Amazon is a multinational technology company that focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. The primary business of Amazon.com is the sale of consumer goods and subscriptions."
hierarchy = ClassHierarchy(
name="company-categorisation",
choices=[
Category(
label="Software company",
criteria="this text contains a description of a software company",
subcategories=[
Category(
label="Ecommerce",
criteria="this text contains a description of an ecommerce company",
),
Category(
label="Blockchain",
criteria="this text contains a description of an web3.0 / blockchain company",
),
],
),
],
)
result = hierarchy_classificaiton(sample_text, hierarchy)
print(result)
# {
# "text": "Amazon is a multinational technology company that focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. The primary business of Amazon.com is the sale of consumer goods and subscriptions.",
# "categories": {
# "category_1": "Software company",
# "category_2": "Ecommerce"
# }