init
Browse files
LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
app.py
ADDED
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from langchain.prompts import FewShotPromptTemplate, PromptTemplate
|
4 |
+
from langchain.llms import OpenAIChat
|
5 |
+
from langchain.callbacks import get_openai_callback
|
6 |
+
from langchain.chains import LLMChain
|
7 |
+
|
8 |
+
|
9 |
+
# Function to generate empty dataframe
|
10 |
+
def create_empty_dataframe(rows, columns):
|
11 |
+
data = {column: [""] * rows for column in columns}
|
12 |
+
return pd.DataFrame(data)
|
13 |
+
|
14 |
+
|
15 |
+
# Sidebar
|
16 |
+
st.sidebar.title("Configuration")
|
17 |
+
selected_model = st.sidebar.selectbox(
|
18 |
+
"Select Model",
|
19 |
+
[
|
20 |
+
"chat-gpt-3.5-turbo",
|
21 |
+
], # "gpt3-text-davinci-003"
|
22 |
+
)
|
23 |
+
selected_dataset = st.sidebar.selectbox(
|
24 |
+
"Select Dataset", ["Regulatory Changes", "Dealer Risk", "Custom"]
|
25 |
+
)
|
26 |
+
openai_api_key = st.sidebar.text_input("OpenAI API Key", type="password")
|
27 |
+
|
28 |
+
|
29 |
+
prompt_prefix = """You are a news recommender and your job is to look at an article and decide if I would find it useful or not.
|
30 |
+
{dataset_specific_prompt}
|
31 |
+
I'm going to pass in a few headlines and publishers. Can you just respond with "Relevant" or "Not Relevant" for the headlines I send you?"""
|
32 |
+
|
33 |
+
if selected_dataset == "Regulatory Changes":
|
34 |
+
dataset_specific_prompt = """I work in a bank/credit card company and I'm looking for news articles that deal with changes in the regulatory environment.
|
35 |
+
It could be articles about regulatory authorities like CFPB or OCC announcing changes in regulation or a new focus areas.
|
36 |
+
Or articles like the president or senate or government announcing new regulations.
|
37 |
+
Or peer financial institutions getting fined for violations.
|
38 |
+
To reiterate I'm especially looking for articles in the finance, fin-tech, banking and credit card sector.
|
39 |
+
**I don't need think pieces or opinion pieces or editorials that talk about the consequences of a regulation but just the ones that talk about objective changes in the regulatory environment that might impact my work**"""
|
40 |
+
examples = [
|
41 |
+
{
|
42 |
+
"headline": "CFPB Launches Inquiry Into the Business Practices of Data Brokers",
|
43 |
+
"publisher": "CFPB",
|
44 |
+
"answer": "Relevant",
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"headline": "OCC Issues Prohibition Order, Fines Former Wells Fargo Executive $17 Million in Settlement",
|
48 |
+
"publisher": "NYT",
|
49 |
+
"answer": "Relevant",
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"headline": "CFPB Announces Appointments of New Advisory Committee Members",
|
53 |
+
"publisher": "CFPB",
|
54 |
+
"answer": "Not Relevant",
|
55 |
+
},
|
56 |
+
]
|
57 |
+
prediction_examples = [
|
58 |
+
{
|
59 |
+
"headline": "Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation",
|
60 |
+
"publisher": "Yahoo Entertainment",
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"headline": "Financial Regulators, Black History and Epistemic Capital",
|
64 |
+
"publisher": "Harvard School of Engineering",
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"headline": "Agencies Issue Joint Statement on Crypto-Asset Risks to Banking Organizations",
|
68 |
+
"publisher": "OCC",
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"headline": "Innovating during a regulatory wave",
|
72 |
+
"publisher": "Venture beat",
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"headline": "CFPB Proposes Rule to Rein in Excessive Credit Card Late Fees",
|
76 |
+
"publisher": "CFPB",
|
77 |
+
},
|
78 |
+
]
|
79 |
+
|
80 |
+
elif selected_dataset == "Dealer Risk":
|
81 |
+
dataset_specific_prompt = """I work in a auto-loan company and I'm looking for news articles that talk about with automobile dealerships being in the news for committing fraud and crime.
|
82 |
+
I am not interested in just about any crime or fraud but only that which is related to dealerships.
|
83 |
+
I am NOT concerned about articles that where the dealership is the victim of a crime.
|
84 |
+
I am only interested where the dealerships are the perpetrators of said crime or accusations.
|
85 |
+
"""
|
86 |
+
examples = [
|
87 |
+
{
|
88 |
+
"headline": "Kentucky Police arrest suspect following $600,000 multiple car heist that took less than 45 seconds",
|
89 |
+
"publisher": "Business Insider",
|
90 |
+
"answer": "Not Relevant",
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"headline": "Car Dealership workers kidnapped, tortured in Armed Robbery",
|
94 |
+
"publisher": "ABC7 Chicago",
|
95 |
+
"answer": "Not Relevant",
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"headline": "Auto Dealership Owner Sentenced to 10 Years in Prison for $1.5 Million Fraud Scheme",
|
99 |
+
"publisher": "Long Island Business News",
|
100 |
+
"answer": "Relevant",
|
101 |
+
},
|
102 |
+
]
|
103 |
+
prediction_examples = [
|
104 |
+
{
|
105 |
+
"headline": "New York City Pharmacist charged with running healthcare fraud scheme",
|
106 |
+
"publisher": "amnycom",
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"headline": "California man arrested for 3.6 million paycheck protection program fraud",
|
110 |
+
"publisher": "DoJ",
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"headline": "Former Moline Businessman sentenced to 41 months in connection with scam to rollback odometeres at used car dealerships",
|
114 |
+
"publisher": "DoJ",
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"headline": "Kentucky car dealer convicted in truck warranty fraud scheme",
|
118 |
+
"publisher": "apnews.com",
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"headline": "Owner of car dealership pleads guilty to defraduing financing company",
|
122 |
+
"publisher": "Automotive News",
|
123 |
+
},
|
124 |
+
]
|
125 |
+
|
126 |
+
elif selected_dataset == "Custom":
|
127 |
+
dataset_specific_prompt = """I work in a XYZ company and I'm looking for news articles that deal with XYZ"""
|
128 |
+
examples = [{k: "" for k in ["headline", "publisher", "answer"]} for i in range(3)]
|
129 |
+
prediction_examples = [{k: "" for k in ["headline", "publisher"]} for i in range(5)]
|
130 |
+
|
131 |
+
|
132 |
+
prompt_prefix = prompt_prefix.format(
|
133 |
+
dataset_specific_prompt=dataset_specific_prompt
|
134 |
+
).replace("\n", " ")
|
135 |
+
|
136 |
+
|
137 |
+
# Main panel
|
138 |
+
st.title("News Topic Subscription")
|
139 |
+
|
140 |
+
st.header("Dataset")
|
141 |
+
st.write(f"Prompt data for {selected_dataset}:")
|
142 |
+
|
143 |
+
prompt_data = st.text_area(
|
144 |
+
"Prompt Prefix", prompt_prefix, placeholder="Enter dataset prompt here", height=300
|
145 |
+
)
|
146 |
+
|
147 |
+
st.header("Few Shot Examples")
|
148 |
+
|
149 |
+
columns = ["headline", "publisher", "answer"]
|
150 |
+
data = pd.DataFrame({k: v for k, v in example.items()} for example in examples)
|
151 |
+
data.columns = columns
|
152 |
+
# data["Relevance"] = [""] * 3
|
153 |
+
|
154 |
+
for index, row in data.iterrows():
|
155 |
+
row["headline"] = st.text_input(
|
156 |
+
f"Headline", row["headline"], key=f"headline_{index}"
|
157 |
+
)
|
158 |
+
row["publisher"] = st.text_input(
|
159 |
+
f"Publisher", row["publisher"], key=f"publisher_{index}"
|
160 |
+
)
|
161 |
+
choice_index = (
|
162 |
+
["Relevant", "Not Relevant"].index(row["answer"]) if row["answer"] != "" else 0
|
163 |
+
)
|
164 |
+
row["answer"] = st.radio(
|
165 |
+
f"Relevance {index + 1}",
|
166 |
+
index=choice_index,
|
167 |
+
options=["Relevant", "Not Relevant"],
|
168 |
+
key=f"answer_{index}",
|
169 |
+
)
|
170 |
+
st.markdown("---")
|
171 |
+
|
172 |
+
st.header("Predictions")
|
173 |
+
|
174 |
+
predictions_data = pd.DataFrame(
|
175 |
+
{k: v for k, v in example.items()} for example in prediction_examples
|
176 |
+
)
|
177 |
+
predictions_data["answer"] = [""] * 5
|
178 |
+
prediction_labels = []
|
179 |
+
|
180 |
+
for index, row in predictions_data.iterrows():
|
181 |
+
row["headline"] = st.text_input(
|
182 |
+
f"headline", row["headline"], key=f"prediction_headline_{index}"
|
183 |
+
)
|
184 |
+
row["publisher"] = st.text_input(
|
185 |
+
f"publisher", row["publisher"], key=f"prediction_publisher_{index}"
|
186 |
+
)
|
187 |
+
prediction_labels.append(st.empty())
|
188 |
+
st.markdown("---")
|
189 |
+
|
190 |
+
|
191 |
+
llm = OpenAIChat(temperature=0.0, openai_api_key=openai_api_key)
|
192 |
+
example_prompt = PromptTemplate(
|
193 |
+
input_variables=["headline", "publisher", "answer"],
|
194 |
+
template="Headline: {headline}\nPublisher: {publisher}\nAnswer: {answer}",
|
195 |
+
)
|
196 |
+
|
197 |
+
|
198 |
+
def update_relevance(predictions_data):
|
199 |
+
|
200 |
+
prompt = FewShotPromptTemplate(
|
201 |
+
prefix=prompt_data,
|
202 |
+
examples=data.to_dict("records"),
|
203 |
+
example_prompt=example_prompt,
|
204 |
+
suffix="Headline: {headline}\nPublisher: {publisher}\nAnswer: ",
|
205 |
+
input_variables=["headline", "publisher"],
|
206 |
+
)
|
207 |
+
print(prompt.format(headline="", publisher=""))
|
208 |
+
print(data)
|
209 |
+
news_predictor_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)
|
210 |
+
token_counts = []
|
211 |
+
|
212 |
+
for index, row in predictions_data.iterrows():
|
213 |
+
if row["headline"] != "":
|
214 |
+
with get_openai_callback() as cb:
|
215 |
+
predictions_data.loc[index, "answer"] = news_predictor_chain.run(
|
216 |
+
{
|
217 |
+
"headline": row["headline"],
|
218 |
+
"publisher": row["publisher"]
|
219 |
+
if row["publisher"] != ""
|
220 |
+
else "Unknown",
|
221 |
+
}
|
222 |
+
)
|
223 |
+
token_counts.append(cb.total_tokens)
|
224 |
+
|
225 |
+
else:
|
226 |
+
predictions_data.loc[index, "answer"] = ""
|
227 |
+
st.text(
|
228 |
+
f"{sum(token_counts)} tokens used in this run for {len(token_counts)} articles. This costed ${sum(token_counts) * 0.002/1000 } @$0.002/1K tokens."
|
229 |
+
)
|
230 |
+
st.text(
|
231 |
+
f"For predicting 1000 articles, it would cost ${sum(token_counts)/len(token_counts) * 0.002 } at the current rate. "
|
232 |
+
)
|
233 |
+
return predictions_data
|
234 |
+
|
235 |
+
|
236 |
+
if st.button("Run Model", type="primary"):
|
237 |
+
predictions_data = update_relevance(predictions_data)
|
238 |
+
for index, row in predictions_data.iterrows():
|
239 |
+
if row["answer"] != "":
|
240 |
+
with prediction_labels[index].container():
|
241 |
+
if row["answer"] == "Relevant":
|
242 |
+
st.markdown("This article is **Relevant** :thumbsup:")
|
243 |
+
else:
|
244 |
+
st.markdown("This article is **Not Relevant** :thumbsdown:")
|
int.ipynb
ADDED
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"id": "7114fd1c-671c-4616-a4fc-19ec40a8423f",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from langchain.prompts import FewShotPromptTemplate\n",
|
11 |
+
"from langchain.llms import OpenAIChat\n",
|
12 |
+
"from langchain.callbacks import get_openai_callback\n",
|
13 |
+
"from langchain.chains import LLMChain\n",
|
14 |
+
"import requests\n",
|
15 |
+
"import datetime\n",
|
16 |
+
"\n",
|
17 |
+
"\n",
|
18 |
+
"\n",
|
19 |
+
"%reload_ext lab_black"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": null,
|
25 |
+
"id": "295d30ed-ba52-43ab-8df0-4c7b8f9b663e",
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [],
|
28 |
+
"source": [
|
29 |
+
"# url = 'https://newsapi.org/v2/sources'\n",
|
30 |
+
"# params = {\n",
|
31 |
+
"# 'apiKey': NEWS_API_KEY\n",
|
32 |
+
"# }\n",
|
33 |
+
"\n",
|
34 |
+
"# response = requests.get(url, params=params)\n",
|
35 |
+
"\n",
|
36 |
+
"# sources = response.json()['sources']\n",
|
37 |
+
"\n",
|
38 |
+
"# for source in sources:\n",
|
39 |
+
"# print(source['id'], '-', source['name'])"
|
40 |
+
]
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "code",
|
44 |
+
"execution_count": null,
|
45 |
+
"id": "122e6596-286b-4fbf-b29f-f1e8db9434f6",
|
46 |
+
"metadata": {},
|
47 |
+
"outputs": [],
|
48 |
+
"source": [
|
49 |
+
"finance_regulatory_bodies = [\n",
|
50 |
+
" \"Consumer Financial Protection Bureau\",\n",
|
51 |
+
" \"CFPB\",\n",
|
52 |
+
" \"Federal Reserve System\",\n",
|
53 |
+
" \"The Fed\",\n",
|
54 |
+
" \"Securities and Exchange Commission\",\n",
|
55 |
+
" \"SEC\",\n",
|
56 |
+
" \"Commodity Futures Trading Commission\",\n",
|
57 |
+
" \"CFTC\",\n",
|
58 |
+
" \"National Credit Union Administration\",\n",
|
59 |
+
" \"NCUA\",\n",
|
60 |
+
" \"Office of the Comptroller of the Currency\",\n",
|
61 |
+
" \"OCC\",\n",
|
62 |
+
" \"Financial Industry Regulatory Authority\",\n",
|
63 |
+
" \"FINRA\",\n",
|
64 |
+
" \"Financial Stability Oversight Council\",\n",
|
65 |
+
" \"FSOC\",\n",
|
66 |
+
" \"Internal Revenue Service\",\n",
|
67 |
+
" \"IRS\",\n",
|
68 |
+
"]\n",
|
69 |
+
"\n",
|
70 |
+
"finance_regulatory_bodies = \" OR \".join(\n",
|
71 |
+
" [f\"'{s.lower()}'\" for s in finance_regulatory_bodies]\n",
|
72 |
+
")\n",
|
73 |
+
"\n",
|
74 |
+
"query = f\"(regulation OR compliance OR legislation) AND (cfpb OR finra OR OCC)\"\n",
|
75 |
+
"# \"law OR regulation OR policy OR compliance OR legislation OR government oversight\"\n",
|
76 |
+
"# categories = \"business,technology,general\" # \"category\": categories,\n",
|
77 |
+
"from_date = datetime.datetime.now() - datetime.timedelta(days=7)\n",
|
78 |
+
"to_date = datetime.datetime.now()\n",
|
79 |
+
"\n",
|
80 |
+
"url = \"https://newsapi.org/v2/everything\"\n",
|
81 |
+
"params = {\n",
|
82 |
+
" \"q\": query,\n",
|
83 |
+
" \"from\": from_date,\n",
|
84 |
+
" \"to\": to_date,\n",
|
85 |
+
" \"language\": \"en\",\n",
|
86 |
+
" \"sortBy\": \"publishedAt\",\n",
|
87 |
+
" \"pageSize\": 100,\n",
|
88 |
+
" \"page\": 1,\n",
|
89 |
+
" \"apiKey\": NEWS_API_KEY,\n",
|
90 |
+
"}\n",
|
91 |
+
"\n",
|
92 |
+
"response = requests.get(url, params=params)"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "code",
|
97 |
+
"execution_count": null,
|
98 |
+
"id": "6fb7e1b8-642a-456b-a161-91f6993edfc8",
|
99 |
+
"metadata": {},
|
100 |
+
"outputs": [],
|
101 |
+
"source": [
|
102 |
+
"articles = response.json()[\"articles\"]"
|
103 |
+
]
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"cell_type": "code",
|
107 |
+
"execution_count": null,
|
108 |
+
"id": "6f4784f7-61d4-4d8f-8b55-29c1373c2cb7",
|
109 |
+
"metadata": {},
|
110 |
+
"outputs": [
|
111 |
+
{
|
112 |
+
"name": "stdout",
|
113 |
+
"output_type": "stream",
|
114 |
+
"text": [
|
115 |
+
"How about some more federal laws to fix banking? - Americanthinker.com - 2023-03-18T05:00:00Z\n",
|
116 |
+
"Bragar Eagel & Squire, P.C. Reminds Investors That Class Action Lawsuits Have Been Filed Against Block, Atlassian, PLDT, and Global Payments and Encourages Investors to Contact the Firm - GlobeNewswire - 2023-03-18T01:00:00Z\n",
|
117 |
+
"Innovating during a regulatory wave - VentureBeat - 2023-03-17T20:07:00Z\n",
|
118 |
+
"Consumer Watchdog Wants to Know Who's Watching Your Internet Behavior - Investopedia - 2023-03-17T15:26:26Z\n",
|
119 |
+
"Regulators Shut Down Banks, Raising Questions About Neutrality - Forbes - 2023-03-17T11:30:00Z\n",
|
120 |
+
"Moomoo's Continuous Innovation Journey on AWS - PRNewswire - 2023-03-17T11:00:00Z\n",
|
121 |
+
"Regulatory Failure 101: What the Collapse of Silicon Valley Bank Reveals - ProPublica - 2023-03-17T11:00:00Z\n",
|
122 |
+
"So Where Were the Regulators? - The Atlantic - 2023-03-17T11:00:00Z\n",
|
123 |
+
"Buy-backs of shares in CoinShares International Limited - Marketscreener.com - 2023-03-17T08:01:01Z\n",
|
124 |
+
"Buy-backs of shares in CoinShares International Limited - Yahoo Entertainment - 2023-03-17T08:00:00Z\n",
|
125 |
+
"Buy-backs of shares in CoinShares International Limited - GlobeNewswire - 2023-03-17T08:00:00Z\n",
|
126 |
+
"Bank Runs, Busts, and Bailouts Are Back. What It Means for Regulations and the Industry. - Barron's - 2023-03-17T06:52:39Z\n",
|
127 |
+
"AdvisorVault Partners With Compliant Workspace to Help FINRA Firms Achieve 17a-4 Compliance on Microsoft 365 - Yahoo Entertainment - 2023-03-17T01:06:00Z\n",
|
128 |
+
"Silicon Valley Bank ex-CEO backed Big Tech lobbying groups that targeted Dodd Frank, sought corporate tax cuts - CNBC - 2023-03-16T17:02:22Z\n",
|
129 |
+
"Blockchain Association seeks info from Fed, FDIC, and OCC on 'de-banking' crypto firms - Cointelegraph - 2023-03-16T16:45:00Z\n",
|
130 |
+
"Baldwin Mader Law Group Wins $6.1 Million Arbitration Award Against Fisker, Inc. - Yahoo Entertainment - 2023-03-16T15:45:00Z\n",
|
131 |
+
"What is Trading Software Development? - Thefrisky.com - 2023-03-16T14:30:58Z\n",
|
132 |
+
"INX ANNOUNCES INTEGRATION WITH POLYGON - Yahoo Entertainment - 2023-03-16T13:48:00Z\n",
|
133 |
+
"AI CEO on GPT-4: This Can Get “Super-Dangerous Very Quickly” - Futurism - 2023-03-16T13:43:43Z\n",
|
134 |
+
"INX ANNOUNCES INTEGRATION WITH POLYGON - PR Newswire UK - 2023-03-16T13:31:00Z\n",
|
135 |
+
"INX ANNOUNCES INTEGRATION WITH POLYGON - Marketscreener.com - 2023-03-16T13:14:03Z\n",
|
136 |
+
"INX ANNOUNCES INTEGRATION WITH POLYGON - Yahoo Entertainment - 2023-03-16T13:13:00Z\n",
|
137 |
+
"INX ANNOUNCES INTEGRATION WITH POLYGON - PRNewswire - 2023-03-16T13:13:00Z\n",
|
138 |
+
"CFPB Launches Long Overdue Probe Of Unaccountable Data Broker Market - Techdirt - 2023-03-16T12:36:58Z\n",
|
139 |
+
"Hashdex Celebrates Six-Month Anniversary of World’s First Bitcoin Futures ETF Registered Solely Under ‘33 Act by Ringing NYSE Opening Bell - GlobeNewswire - 2023-03-16T12:35:00Z\n",
|
140 |
+
"GigaStar, a Startup Bringing YouTube Creators and Fans Together as Partners, Completes a $4.8 Million Seed Round - PRNewswire - 2023-03-16T11:00:00Z\n",
|
141 |
+
"Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation - Yahoo Entertainment - 2023-03-15T22:41:59Z\n",
|
142 |
+
"Sterling Bancorp, Inc. Enters Into Plea Agreement with DOJ; Resolves DOJ Investigation of the Company Relating to the Advantage Loan Program; Revises Fourth Quarter and Full Year 2022 Unaudited Financial Results - Marketscreener.com - 2023-03-15T21:13:02Z\n",
|
143 |
+
"Retail Traders Left Hanging As Brokers Halt Transactions On Silicon Valley Bank Just As Bets Are Set To Pay Off - Forbes - 2023-03-15T19:27:06Z\n",
|
144 |
+
"How the 2008 financial crisis fuels today's populist politics - PBS - 2023-03-15T17:58:06Z\n",
|
145 |
+
"Patti Brennan Ranks # 5 in Barron s Top 1,200 Financial Advisors State by State - GlobeNewswire - 2023-03-15T17:25:00Z\n",
|
146 |
+
"Patti Brennan Ranks # 5 in Barron s Top 1,200 Financial Advisors State by State - Yahoo Entertainment - 2023-03-15T17:25:00Z\n",
|
147 |
+
"GoLogiq to Acquire Institutional Investment Advisory Firm, CPG Research & Advisory, in $15 Million Merger - GlobeNewswire - 2023-03-15T17:00:00Z\n",
|
148 |
+
"GoLogiq to Acquire Institutional Investment Advisory Firm, CPG Research & Advisory, in $15 Million Merger - Yahoo Entertainment - 2023-03-15T17:00:00Z\n",
|
149 |
+
"Webinar: Navigating Marketing Compliance Challenges in 2023 - Performline.com - 2023-03-15T16:24:05Z\n",
|
150 |
+
"Financial Regulators, Black History and Epistemic Capital - Harvard School of Engineering and Applied Sciences - 2023-03-15T13:30:43Z\n",
|
151 |
+
"How the last banking tumult fuels today's populist politics - seattlepi.com - 2023-03-15T12:20:48Z\n",
|
152 |
+
"How the last banking tumult fuels today's populist politics - ABC News - 2023-03-15T10:32:20Z\n",
|
153 |
+
"How the last banking tumult fuels today's populist politics - ABC News - 2023-03-15T10:32:12Z\n",
|
154 |
+
"How the last banking tumult fuels today's populist politics - Independent - 2023-03-15T10:00:45Z\n",
|
155 |
+
"How the last banking tumult fuels today's populist politics - Yahoo Entertainment - 2023-03-15T10:00:44Z\n",
|
156 |
+
"Central Pacific Financial : CPF Balance Sheet Update - Marketscreener.com - 2023-03-15T00:00:07Z\n",
|
157 |
+
"Bowman, The Innovation Imperative: Modernizing Traditional Banking - Federalreserve.gov - 2023-03-14T21:20:00Z\n",
|
158 |
+
"SVB collapse creates rift among Democrats over 2018 banking law - Yahoo Entertainment - 2023-03-14T20:53:04Z\n",
|
159 |
+
"Enterprise Health Sponsors ACOEM Ambassador Program - Yahoo Entertainment - 2023-03-14T15:42:00Z\n",
|
160 |
+
"Community Reinvestment Act (CRA) Expert Sarah Brons Joins Asurity's RiskExec Team - PRNewswire - 2023-03-14T15:02:00Z\n",
|
161 |
+
"Tom Oscherwitz Joins Informed.IQ as VP of Legal and Regulatory Advisor - PRNewswire - 2023-03-14T13:40:00Z\n",
|
162 |
+
"Biden Highlights Dodd-Frank Repeal in Calls for Stiffer Bank Regulations - Investopedia - 2023-03-14T11:33:00Z\n",
|
163 |
+
"Republicans Who Pushed for Financial Deregulation Blame Silicon Valley Bank Collapse on “Woke Agenda” - The New Republic - 2023-03-13T22:06:50Z\n",
|
164 |
+
"USDC's 'Black Swan' Depegging Could Have Been Avoided With Proper Regulatory Framework - CoinDesk - 2023-03-13T21:59:35Z\n",
|
165 |
+
"How Silicon Valley Bank skirted Washington's toughest banking rules - Yahoo Entertainment - 2023-03-13T21:55:01Z\n",
|
166 |
+
"It’s Not Just Fraud That Chilled Crypto Regulation - CoinDesk - 2023-03-13T20:56:08Z\n",
|
167 |
+
"SVB Moral: Idiot Businesses Get a Bailout—and Indebted College Kids Get Lawsuits - The New Republic - 2023-03-13T20:23:18Z\n",
|
168 |
+
"Fed announces regulatory review of Silicon Valley Bank failure - Yahoo Entertainment - 2023-03-13T20:22:21Z\n",
|
169 |
+
"INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Yahoo Entertainment - 2023-03-13T15:13:00Z\n",
|
170 |
+
"INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - PR Newswire UK - 2023-03-13T14:54:00Z\n",
|
171 |
+
"INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Marketscreener.com - 2023-03-13T14:39:04Z\n",
|
172 |
+
"INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Yahoo Entertainment - 2023-03-13T14:38:00Z\n",
|
173 |
+
"INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - PRNewswire - 2023-03-13T14:38:00Z\n",
|
174 |
+
"The Impact Of Evolving Cloud Regulations On Financial Services - Forbes - 2023-03-13T12:45:00Z\n",
|
175 |
+
"Bragar Eagel & Squire, P.C. Reminds Investors That Class Action Lawsuits Have Been Filed Against Global Payments, Caribou, Inspirato, and Kornit and Encourages Investors to Contact the Firm - GlobeNewswire - 2023-03-13T01:00:00Z\n"
|
176 |
+
]
|
177 |
+
}
|
178 |
+
],
|
179 |
+
"source": [
|
180 |
+
"for article in articles:\n",
|
181 |
+
" print(article[\"title\"], \"-\", article[\"source\"][\"name\"], \"-\", article[\"publishedAt\"])"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"cell_type": "markdown",
|
186 |
+
"id": "b3758b70-c1f8-41dd-8a2b-5d000e851fed",
|
187 |
+
"metadata": {},
|
188 |
+
"source": [
|
189 |
+
"# Langchain"
|
190 |
+
]
|
191 |
+
},
|
192 |
+
{
|
193 |
+
"cell_type": "code",
|
194 |
+
"execution_count": null,
|
195 |
+
"id": "a21af9b3-6376-4226-81df-377d774f4a99",
|
196 |
+
"metadata": {},
|
197 |
+
"outputs": [],
|
198 |
+
"source": [
|
199 |
+
"llm = OpenAIChat(temperature=0.0)"
|
200 |
+
]
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"cell_type": "code",
|
204 |
+
"execution_count": null,
|
205 |
+
"id": "87936389-312c-49de-a88d-40a7ad82a06d",
|
206 |
+
"metadata": {},
|
207 |
+
"outputs": [],
|
208 |
+
"source": [
|
209 |
+
"# Also, I don't need any article that talks about regulation but rather something that discusses a regulatory change that might impact my work"
|
210 |
+
]
|
211 |
+
},
|
212 |
+
{
|
213 |
+
"cell_type": "code",
|
214 |
+
"execution_count": null,
|
215 |
+
"id": "aae3283e-b042-4618-9070-073303985527",
|
216 |
+
"metadata": {},
|
217 |
+
"outputs": [],
|
218 |
+
"source": [
|
219 |
+
"prefix = \"\"\"You are a news recommender and your job is to look at an article and decide if I would find it useful or not.\n",
|
220 |
+
"I work in a bank/credit card company and I'm looking for news articles that deal with changes in the regulatory environment. \n",
|
221 |
+
"It could be articles about regulatory authorities like CFPB or OCC announcing changes in regulation or a new focus areas. \n",
|
222 |
+
"Or articles like the president or senate or government announcing new regulations. \n",
|
223 |
+
"Or peer financial institutions getting fined for violations. \n",
|
224 |
+
"To reiterate I'm especially looking for articles in the finance, fin-tech, banking and credit card sector. \n",
|
225 |
+
"**I don't need think pieces or opinion pieces or editorials that talk about the consequences of a regulation but just the ones that talk about objective changes in the regulatory environment that might impact my work**\n",
|
226 |
+
"I'm going to pass in a few headlines. Can you just respond with \"relevant\" or \"not relevant\" for the headlines I send you?\"\"\"\n",
|
227 |
+
"\n",
|
228 |
+
"examples = [\n",
|
229 |
+
" {\n",
|
230 |
+
" \"headline\": \"CFPB Launches Inquiry Into the Business Practices of Data Brokers\",\n",
|
231 |
+
" \"publisher\": \"CFPB\",\n",
|
232 |
+
" \"answer\": \"relevant\",\n",
|
233 |
+
" },\n",
|
234 |
+
" {\n",
|
235 |
+
" \"headline\": \"OCC Issues Prohibition Order, Fines Former Wells Fargo Executive $17 Million in Settlement\",\n",
|
236 |
+
" \"publisher\": \"NYT\",\n",
|
237 |
+
" \"answer\": \"relevant\",\n",
|
238 |
+
" },\n",
|
239 |
+
" {\n",
|
240 |
+
" \"headline\": \"Innovating during a regulatory wave\",\n",
|
241 |
+
" \"publisher\": \"Venture beat\",\n",
|
242 |
+
" \"answer\": \"not relevant\",\n",
|
243 |
+
" },\n",
|
244 |
+
"]"
|
245 |
+
]
|
246 |
+
},
|
247 |
+
{
|
248 |
+
"cell_type": "code",
|
249 |
+
"execution_count": null,
|
250 |
+
"id": "07b77a00-3f61-4d4f-9ff5-fbe330e7e6b2",
|
251 |
+
"metadata": {},
|
252 |
+
"outputs": [],
|
253 |
+
"source": [
|
254 |
+
"example_prompt = PromptTemplate(\n",
|
255 |
+
" input_variables=[\"headline\", \"publisher\", \"answer\"],\n",
|
256 |
+
" template=\"Headline: {headline}\\nPublisher: {publisher}\\nAnswer: {answer}\",\n",
|
257 |
+
")"
|
258 |
+
]
|
259 |
+
},
|
260 |
+
{
|
261 |
+
"cell_type": "code",
|
262 |
+
"execution_count": null,
|
263 |
+
"id": "da1d7f5d-bd1b-489f-ac80-804ccc241fa4",
|
264 |
+
"metadata": {},
|
265 |
+
"outputs": [],
|
266 |
+
"source": [
|
267 |
+
"prompt = FewShotPromptTemplate(\n",
|
268 |
+
" prefix=prefix,\n",
|
269 |
+
" examples=examples,\n",
|
270 |
+
" example_prompt=example_prompt,\n",
|
271 |
+
" suffix=\"Headline: {headline}\\nPublisher: {publisher}\\nAnswer: \",\n",
|
272 |
+
" input_variables=[\"headline\", \"publisher\"],\n",
|
273 |
+
")"
|
274 |
+
]
|
275 |
+
},
|
276 |
+
{
|
277 |
+
"cell_type": "code",
|
278 |
+
"execution_count": null,
|
279 |
+
"id": "51216122-1424-4f85-9d72-a094f644f90c",
|
280 |
+
"metadata": {},
|
281 |
+
"outputs": [
|
282 |
+
{
|
283 |
+
"name": "stdout",
|
284 |
+
"output_type": "stream",
|
285 |
+
"text": [
|
286 |
+
"You are a news recommender and your job is to look at an article and decide if I would find it useful or not.\n",
|
287 |
+
"I work in a bank/credit card company and I'm looking for news articles that deal with changes in the regulatory environment. \n",
|
288 |
+
"It could be articles about regulatory authorities like CFPB or OCC announcing changes in regulation or a new focus areas. \n",
|
289 |
+
"Or articles like the president or senate or government announcing new regulations. \n",
|
290 |
+
"Or peer financial institutions getting fined for violations. \n",
|
291 |
+
"To reiterate I'm especially looking for articles in the finance, fin-tech, banking and credit card sector. \n",
|
292 |
+
"**I don't need think pieces or opinion pieces or editorials that talk about the consequences of a regulation but just the ones that talk about objective changes in the regulatory environment that might impact my work**\n",
|
293 |
+
"I'm going to pass in a few headlines. Can you just respond with \"relevant\" or \"not relevant\" for the headlines I send you?\n",
|
294 |
+
"\n",
|
295 |
+
"\n",
|
296 |
+
"\n",
|
297 |
+
"Headline: CFPB Launches Inquiry Into the Business Practices of Data Brokers\n",
|
298 |
+
"Publisher: CFPB\n",
|
299 |
+
"Answer: relevant\n",
|
300 |
+
"\n",
|
301 |
+
"Headline: OCC Issues Prohibition Order, Fines Former Wells Fargo Executive $17 Million in Settlement\n",
|
302 |
+
"Publisher: NYT\n",
|
303 |
+
"Answer: relevant\n",
|
304 |
+
"\n",
|
305 |
+
"Headline: Innovating during a regulatory wave\n",
|
306 |
+
"Publisher: Venture beat\n",
|
307 |
+
"Answer: not relevant\n",
|
308 |
+
"\n",
|
309 |
+
"Headline: CFPB Launches Inquiry Into the Business Practices of Data Brokers\n",
|
310 |
+
"Publisher: CFPB\n",
|
311 |
+
"Answer: \n"
|
312 |
+
]
|
313 |
+
}
|
314 |
+
],
|
315 |
+
"source": [
|
316 |
+
"print(\n",
|
317 |
+
" prompt.format(\n",
|
318 |
+
" **{\n",
|
319 |
+
" \"headline\": \"CFPB Launches Inquiry Into the Business Practices of Data Brokers\",\n",
|
320 |
+
" \"publisher\": \"CFPB\",\n",
|
321 |
+
" }\n",
|
322 |
+
" )\n",
|
323 |
+
")"
|
324 |
+
]
|
325 |
+
},
|
326 |
+
{
|
327 |
+
"cell_type": "code",
|
328 |
+
"execution_count": null,
|
329 |
+
"id": "d1bcdf3a-c41c-4815-a802-7903e6ce43b2",
|
330 |
+
"metadata": {},
|
331 |
+
"outputs": [],
|
332 |
+
"source": [
|
333 |
+
"news_predictor_chain = LLMChain(prompt=prompt, llm=llm)"
|
334 |
+
]
|
335 |
+
},
|
336 |
+
{
|
337 |
+
"cell_type": "code",
|
338 |
+
"execution_count": null,
|
339 |
+
"id": "c1dc07e5-e2fb-4a5b-8078-de83a3c8e1d4",
|
340 |
+
"metadata": {},
|
341 |
+
"outputs": [
|
342 |
+
{
|
343 |
+
"data": {
|
344 |
+
"text/plain": [
|
345 |
+
"{'headline': 'Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation',\n",
|
346 |
+
" 'publisher': 'Yahoo Entertainment',\n",
|
347 |
+
" 'text': 'not relevant'}"
|
348 |
+
]
|
349 |
+
},
|
350 |
+
"execution_count": null,
|
351 |
+
"metadata": {},
|
352 |
+
"output_type": "execute_result"
|
353 |
+
}
|
354 |
+
],
|
355 |
+
"source": [
|
356 |
+
"news_predictor_chain.run(\n",
|
357 |
+
" {\n",
|
358 |
+
" \"headline\": \"Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation\",\n",
|
359 |
+
" \"publisher\": \"Yahoo Entertainment\",\n",
|
360 |
+
" }\n",
|
361 |
+
")"
|
362 |
+
]
|
363 |
+
},
|
364 |
+
{
|
365 |
+
"cell_type": "code",
|
366 |
+
"execution_count": null,
|
367 |
+
"id": "91d5dfc2-08ed-417e-abc6-cd961ac62a79",
|
368 |
+
"metadata": {},
|
369 |
+
"outputs": [
|
370 |
+
{
|
371 |
+
"data": {
|
372 |
+
"text/plain": [
|
373 |
+
"{'headline': 'Financial Regulators, Black History and Epistemic Capital',\n",
|
374 |
+
" 'publisher': 'Harvard School of Engineering',\n",
|
375 |
+
" 'text': 'not relevant'}"
|
376 |
+
]
|
377 |
+
},
|
378 |
+
"execution_count": null,
|
379 |
+
"metadata": {},
|
380 |
+
"output_type": "execute_result"
|
381 |
+
}
|
382 |
+
],
|
383 |
+
"source": [
|
384 |
+
"news_predictor_chain.run(\n",
|
385 |
+
" {\n",
|
386 |
+
" \"headline\": \"Financial Regulators, Black History and Epistemic Capital\",\n",
|
387 |
+
" \"publisher\": \"Harvard School of Engineering\",\n",
|
388 |
+
" }\n",
|
389 |
+
")"
|
390 |
+
]
|
391 |
+
},
|
392 |
+
{
|
393 |
+
"cell_type": "code",
|
394 |
+
"execution_count": null,
|
395 |
+
"id": "b2b868b0-1d7e-4074-b55d-fab0e8b12bf6",
|
396 |
+
"metadata": {},
|
397 |
+
"outputs": [
|
398 |
+
{
|
399 |
+
"data": {
|
400 |
+
"text/plain": [
|
401 |
+
"{'headline': 'Agencies Issue Joint Statement on Crypto-Asset Risks to Banking Organizations',\n",
|
402 |
+
" 'publisher': 'OCC',\n",
|
403 |
+
" 'text': 'relevant'}"
|
404 |
+
]
|
405 |
+
},
|
406 |
+
"execution_count": null,
|
407 |
+
"metadata": {},
|
408 |
+
"output_type": "execute_result"
|
409 |
+
}
|
410 |
+
],
|
411 |
+
"source": [
|
412 |
+
"news_predictor_chain(\n",
|
413 |
+
" {\n",
|
414 |
+
" \"headline\": \"Agencies Issue Joint Statement on Crypto-Asset Risks to Banking Organizations\",\n",
|
415 |
+
" \"publisher\": \"OCC\",\n",
|
416 |
+
" }\n",
|
417 |
+
")"
|
418 |
+
]
|
419 |
+
},
|
420 |
+
{
|
421 |
+
"cell_type": "code",
|
422 |
+
"execution_count": null,
|
423 |
+
"id": "8d18d0b9-274d-4ae9-8c0e-1dc1e6f42add",
|
424 |
+
"metadata": {},
|
425 |
+
"outputs": [
|
426 |
+
{
|
427 |
+
"data": {
|
428 |
+
"text/plain": [
|
429 |
+
"{'headline': 'Acting Comptroller of the Currency Testifies on Regulatory Priorities',\n",
|
430 |
+
" 'publisher': 'The Washington Post',\n",
|
431 |
+
" 'text': 'relevant'}"
|
432 |
+
]
|
433 |
+
},
|
434 |
+
"execution_count": null,
|
435 |
+
"metadata": {},
|
436 |
+
"output_type": "execute_result"
|
437 |
+
}
|
438 |
+
],
|
439 |
+
"source": [
|
440 |
+
"news_predictor_chain.run(\n",
|
441 |
+
" {\n",
|
442 |
+
" \"headline\": \"Acting Comptroller of the Currency Testifies on Regulatory Priorities\",\n",
|
443 |
+
" \"publisher\": \"The Washington Post\",\n",
|
444 |
+
" }\n",
|
445 |
+
")"
|
446 |
+
]
|
447 |
+
},
|
448 |
+
{
|
449 |
+
"cell_type": "code",
|
450 |
+
"execution_count": null,
|
451 |
+
"id": "fe55edc1-43f3-4e13-a3f7-53f24593a0a5",
|
452 |
+
"metadata": {},
|
453 |
+
"outputs": [
|
454 |
+
{
|
455 |
+
"data": {
|
456 |
+
"text/plain": [
|
457 |
+
"{'headline': 'The Impact Of Evolving Cloud Regulations On Financial Services',\n",
|
458 |
+
" 'publisher': 'Forbes',\n",
|
459 |
+
" 'text': 'relevant'}"
|
460 |
+
]
|
461 |
+
},
|
462 |
+
"execution_count": null,
|
463 |
+
"metadata": {},
|
464 |
+
"output_type": "execute_result"
|
465 |
+
}
|
466 |
+
],
|
467 |
+
"source": [
|
468 |
+
"news_predictor_chain.run(\n",
|
469 |
+
" {\n",
|
470 |
+
" \"headline\": \"The Impact Of Evolving Cloud Regulations On Financial Services\",\n",
|
471 |
+
" \"publisher\": \"Forbes\",\n",
|
472 |
+
" }\n",
|
473 |
+
")"
|
474 |
+
]
|
475 |
+
},
|
476 |
+
{
|
477 |
+
"cell_type": "code",
|
478 |
+
"execution_count": null,
|
479 |
+
"id": "d0a45c24-dfff-4af3-897f-5182c21f1d06",
|
480 |
+
"metadata": {},
|
481 |
+
"outputs": [
|
482 |
+
{
|
483 |
+
"data": {
|
484 |
+
"text/plain": [
|
485 |
+
"3"
|
486 |
+
]
|
487 |
+
},
|
488 |
+
"execution_count": null,
|
489 |
+
"metadata": {},
|
490 |
+
"output_type": "execute_result"
|
491 |
+
}
|
492 |
+
],
|
493 |
+
"source": [
|
494 |
+
"sum([1, 2])"
|
495 |
+
]
|
496 |
+
},
|
497 |
+
{
|
498 |
+
"cell_type": "code",
|
499 |
+
"execution_count": null,
|
500 |
+
"id": "e4bc7325-6748-4837-b6b0-bff4467c077b",
|
501 |
+
"metadata": {},
|
502 |
+
"outputs": [],
|
503 |
+
"source": []
|
504 |
+
}
|
505 |
+
],
|
506 |
+
"metadata": {
|
507 |
+
"kernelspec": {
|
508 |
+
"display_name": "Python [conda env:news_ai]",
|
509 |
+
"language": "python",
|
510 |
+
"name": "conda-env-news_ai-py"
|
511 |
+
}
|
512 |
+
},
|
513 |
+
"nbformat": 4,
|
514 |
+
"nbformat_minor": 5
|
515 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
langchain>=0.0.11
|
2 |
+
pandas
|
3 |
+
openai
|