Dagger
Search

categorizeExpenses

This module has been developed to leverage advanced natural language processing capabilities provided by Hugging Face's transformers library to categorize financial transactions into predefined categories. Utilizing the BART large MNLI model, this module interprets transaction descriptions and intelligently classifies them into categories such as Grocery, Snacks, Entertainment, and more, based on the content of the description.

The BART large MNLI model is a classification model trained on a multi-genre natural language inference corpus. It's designed to understand the context of sentences and predict appropriate labels, making it highly effective for tasks like categorizing unstructured text into specific categories.

Categories used for classification include: - **Grocery**: Transactions related to food and general supermarket purchases. - **Snacks**: Small, typically impulsive purchases of food or drinks. - **Takeouts**: Expenses for food ordered from restaurants for consumption off the premises. - **Entertainment**: Transactions related to leisure activities. - **Transportation**: Expenses associated with travel, including fares for buses, trains, taxis, etc. - **Credit Card Payment**: Payments made towards credit card bills. - **Shopping**: General shopping expenses, excluding groceries. - **Personal Care**: Expenses on products or services related to personal hygiene and grooming. - **Healthcare**: Medical or health-related expenses.

This module includes functions to handle the retrieval and processing of transaction data, employing robust error handling and retry logic to manage API limits and ensure reliable operation.

Functions: - `process_batch`: Processes a batch of transactions by submitting descriptions to the Hugging Face model and categorizing them based on the model's predictions. This function handles API responses and segregates processed transactions from those that couldn't be categorized due to errors or API limits. - `categorize`: The main function of the module, orchestrating the retrieval of transaction data, invoking the `process_batch` function, and managing retries in case of failures. It ensures that all transactions are processed, leveraging asynchronous programming to handle potentially large volumes of data efficiently.

Args: - `data (str)`: A JSON string containing an array of transactions, where each transaction includes a description and other relevant details. - `hftoken (Secret)`: A Secret object that contains the API token for accessing the Hugging Face model.

Return: - The function returns a JSON string that represents the categorized transactions. Each transaction in this string includes the original details supplemented with a 'Category' field indicating the classification assigned by the model.

Example Call: `dagger call categorize --data='[{"Description": "Apple purchase at grocery", "Amount": 30}]' --hftoken=env:[KEY]`

Usage of this module can significantly streamline the process of categorizing financial transactions, reducing manual effort and improving the accuracy and consistency of financial record-keeping. It is particularly valuable for applications involving expense management, financial tracking, or any system requiring detailed categorization of transaction data.

Installation

dagger install github.com/EmmS21/daggerverse/categorizeExpenses@v0.0.2

Entrypoint

Return Type
CategorizeExpenses !
Example
dagger -m github.com/EmmS21/daggerverse/categorizeExpenses@38a944be8fb2b71336dee507f6088822ec5f32f5 call \
func (m *myModule) example() *CategorizeExpenses  {
	return dag.
			CategorizeExpenses()
}
@function
def example() -> dag.CategorizeExpenses:
	return (
		dag.categorize_expenses()
	)
@func()
example(): CategorizeExpenses {
	return dag
		.categorizeExpenses()
}

Types

CategorizeExpenses 🔗

categorize() 🔗

Processes transactions using an AI model from Hugging Face with retry logic for API limits.

Return Type
String !
Arguments
NameTypeDefault ValueDescription
dataString !-No description provided
hftokenSecret !-A reference to a secret value, which can be handled more safely than the value itself.
Example
dagger -m github.com/EmmS21/daggerverse/categorizeExpenses@38a944be8fb2b71336dee507f6088822ec5f32f5 call \
 categorize --data string --hftoken env:MYSECRET
func (m *myModule) example(ctx context.Context, data string, hftoken *Secret) string  {
	return dag.
			CategorizeExpenses().
			Categorize(ctx, data, hftoken)
}
@function
async def example(data: str, hftoken: dagger.Secret) -> str:
	return await (
		dag.categorize_expenses()
		.categorize(data, hftoken)
	)
@func()
async example(data: string, hftoken: Secret): Promise<string> {
	return dag
		.categorizeExpenses()
		.categorize(data, hftoken)
}