File size: 2,568 Bytes
71c527f
 
 
9c4e132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
license: gemma
---
This is Gemma 2B model (GGUF Q8_0) fine-tuned for financial aspect based sentiment analysis with structured JSON response.

**Input**
```
financial_text = """Upon auditing Non-Profit Org, it was clear that the organization has made strides in improving financial accountability and donor transparency. 
However, the audit also unveiled significant inefficiencies in fund allocation, signaling a need for better financial oversight to ensure the organization's sustainability and mission effectiveness.
"""
```

**Response**
```json
{
    "Overall_Sentiment": "Mixed",
    "Positive_Aspect": [
        "financial accountability",
        "donor transparency"
    ],
    "Negative_Aspect": [
        "fund allocation inefficiencies",
        "need for financial oversight"
    ]
}
```

### Get started with Langchain
```python
#!pip install --upgrade llama-cpp-python langchain_core langchain_community

from langchain_community.llms import LlamaCpp
from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler

# Callbacks support token-wise streaming
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])

llm = LlamaCpp(
    model_path="Gemma-2B-it-finance-aspect-based-sentiment-gguf-Q8_0.gguf",
    max_tokens=2048,
    temperature=0,
    top_p=1,
    callback_manager=callback_manager,
    verbose=True,  # Verbose is required to pass to the callback manager
)

prompt_template = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
Perform Aspect based sentiment analysis. 
Present your response in python JSON format with "Overall_Sentiment", "Positive_Aspect", "Negative_Aspect".


### Input:
{financial_text}


### Response:
"""

financial_text = """Upon auditing Non-Profit Org, it was clear that the organization has made strides in improving financial accountability and donor transparency. 
However, the audit also unveiled significant inefficiencies in fund allocation, signaling a need for better financial oversight to ensure the organization's sustainability and mission effectiveness.
"""

prompt = prompt_template.format(financial_text=financial_text)

response = llm.invoke(prompt)
```
### Response:
```json
{
    "Overall_Sentiment": "Mixed",
    "Positive_Aspect": [
        "financial accountability",
        "donor transparency"
    ],
    "Negative_Aspect": [
        "fund allocation inefficiencies",
        "need for financial oversight"
    ]
}
```