Upload folder using huggingface_hub
Browse files- .devcontainer/devcontainer.json +33 -0
- .gitattributes +2 -0
- .github/workflows/add_collaborators.yml +51 -0
- .github/workflows/release_archive.yml +18 -0
- .gitignore +173 -0
- COLLABORATORS +4 -0
- Deployment/readme.md +1 -0
- Documentation/Documentation for MAPLE.pdf +3 -0
- Documentation/Research.md +97 -0
- EDA/bills_topics.txt +0 -0
- EDA/eda.ipynb +0 -0
- EDA/primary_sponsor.csv +0 -0
- EDA/top2vec.ipynb +582 -0
- LICENSE +674 -0
- Project_outline.md +73 -0
- Prompts Engineering/prompts.md +44 -0
- Prompts Engineering/readme.md +1 -0
- README.md +43 -0
- Tagging/categories_tagging.md +226 -0
- Tagging/prompts.md +7 -0
- Tagging/readme.md +1 -0
- Tagging/tagging_testing.ipynb +345 -0
- demoapp/12billswithmgl.csv +0 -0
- demoapp/MGL_extract.ipynb +827 -0
- demoapp/README.md +27 -0
- demoapp/all_bills.csv +3 -0
- demoapp/app.py +247 -0
- demoapp/app2.py +286 -0
- demoapp/category.txt +226 -0
- demoapp/extracted_mgl.txt +0 -0
- demoapp/generated_bills.csv +23 -0
- demoapp/requirements.txt +10 -0
- demoapp/sidebar.py +30 -0
- demoapp/tagging.py +330 -0
.devcontainer/devcontainer.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "Python 3",
|
3 |
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
4 |
+
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
|
5 |
+
"customizations": {
|
6 |
+
"codespaces": {
|
7 |
+
"openFiles": [
|
8 |
+
"README.md",
|
9 |
+
"demoapp/app.py"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
"vscode": {
|
13 |
+
"settings": {},
|
14 |
+
"extensions": [
|
15 |
+
"ms-python.python",
|
16 |
+
"ms-python.vscode-pylance"
|
17 |
+
]
|
18 |
+
}
|
19 |
+
},
|
20 |
+
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'",
|
21 |
+
"postAttachCommand": {
|
22 |
+
"server": "streamlit run demoapp/app.py --server.enableCORS false --server.enableXsrfProtection false"
|
23 |
+
},
|
24 |
+
"portsAttributes": {
|
25 |
+
"8501": {
|
26 |
+
"label": "Application",
|
27 |
+
"onAutoForward": "openPreview"
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"forwardPorts": [
|
31 |
+
8501
|
32 |
+
]
|
33 |
+
}
|
.gitattributes
CHANGED
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
Documentation/Documentation[[:space:]]for[[:space:]]MAPLE.pdf filter=lfs diff=lfs merge=lfs -text
|
57 |
+
demoapp/all_bills.csv filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/add_collaborators.yml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Author: Rishab
|
2 |
+
name: Add Collaborators v1.1
|
3 |
+
|
4 |
+
on:
|
5 |
+
push:
|
6 |
+
branches:
|
7 |
+
- master
|
8 |
+
- main
|
9 |
+
- dev
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
add-collaborators:
|
13 |
+
runs-on: ubuntu-latest
|
14 |
+
steps:
|
15 |
+
- name: Checkout Repo
|
16 |
+
uses: actions/checkout@v2
|
17 |
+
- name: Add Collaborators
|
18 |
+
uses: actions/[email protected]
|
19 |
+
with:
|
20 |
+
github-token: ${{secrets.ADMIN_GITHUB_TOKEN}}
|
21 |
+
script: |
|
22 |
+
const fs = require('fs');
|
23 |
+
const readline = require('readline');
|
24 |
+
const readInterface = readline.createInterface({
|
25 |
+
input: fs.createReadStream('./COLLABORATORS'),
|
26 |
+
output: process.stdout,
|
27 |
+
console: false
|
28 |
+
});
|
29 |
+
readInterface.on('line', async function(line) {
|
30 |
+
try {
|
31 |
+
await github.repos.checkCollaborator({
|
32 |
+
owner: context.repo.owner,
|
33 |
+
repo: context.repo.repo,
|
34 |
+
username: line,
|
35 |
+
});
|
36 |
+
} catch(err) {
|
37 |
+
console.log(err)
|
38 |
+
if(err.toString() === "HttpError: Not Found"){
|
39 |
+
await github.repos.addCollaborator({
|
40 |
+
owner: context.repo.owner,
|
41 |
+
repo: context.repo.repo,
|
42 |
+
username: line,
|
43 |
+
permission: 'push'
|
44 |
+
});
|
45 |
+
} else {
|
46 |
+
core.setFailed(err.toString())
|
47 |
+
}
|
48 |
+
|
49 |
+
}
|
50 |
+
});
|
51 |
+
|
.github/workflows/release_archive.yml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Archive Repository into Release v1.0
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
tags:
|
5 |
+
- "spark-archive-*"
|
6 |
+
jobs:
|
7 |
+
tagged-release:
|
8 |
+
name: "Tagged Release"
|
9 |
+
runs-on: "ubuntu-latest"
|
10 |
+
steps:
|
11 |
+
- name: Checkout
|
12 |
+
uses: actions/checkout@v2
|
13 |
+
- name: Release
|
14 |
+
uses: softprops/action-gh-release@v1
|
15 |
+
with:
|
16 |
+
files: |
|
17 |
+
"*.md"
|
18 |
+
"*.MD"
|
.gitignore
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
# Jetbrains Products
|
5 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
6 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
7 |
+
|
8 |
+
# User-specific stuff
|
9 |
+
.idea/**/workspace.xml
|
10 |
+
.idea/**/tasks.xml
|
11 |
+
.idea/**/usage.statistics.xml
|
12 |
+
.idea/**/dictionaries
|
13 |
+
.idea/**/shelf
|
14 |
+
|
15 |
+
# AWS User-specific
|
16 |
+
.idea/**/aws.xml
|
17 |
+
|
18 |
+
# Generated files
|
19 |
+
.idea/**/contentModel.xml
|
20 |
+
|
21 |
+
# Sensitive or high-churn files
|
22 |
+
.idea/**/dataSources/
|
23 |
+
.idea/**/dataSources.ids
|
24 |
+
.idea/**/dataSources.local.xml
|
25 |
+
.idea/**/sqlDataSources.xml
|
26 |
+
.idea/**/dynamic.xml
|
27 |
+
.idea/**/uiDesigner.xml
|
28 |
+
.idea/**/dbnavigator.xml
|
29 |
+
|
30 |
+
# Gradle
|
31 |
+
.idea/**/gradle.xml
|
32 |
+
.idea/**/libraries
|
33 |
+
|
34 |
+
# Gradle and Maven with auto-import
|
35 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
36 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
37 |
+
# auto-import.
|
38 |
+
# .idea/artifacts
|
39 |
+
# .idea/compiler.xml
|
40 |
+
# .idea/jarRepositories.xml
|
41 |
+
# .idea/modules.xml
|
42 |
+
# .idea/*.iml
|
43 |
+
# .idea/modules
|
44 |
+
# *.iml
|
45 |
+
# *.ipr
|
46 |
+
|
47 |
+
# CMake
|
48 |
+
cmake-build-*/
|
49 |
+
|
50 |
+
# Mongo Explorer plugin
|
51 |
+
.idea/**/mongoSettings.xml
|
52 |
+
|
53 |
+
# File-based project format
|
54 |
+
*.iws
|
55 |
+
|
56 |
+
# IntelliJ
|
57 |
+
out/
|
58 |
+
|
59 |
+
# mpeltonen/sbt-idea plugin
|
60 |
+
.idea_modules/
|
61 |
+
|
62 |
+
# JIRA plugin
|
63 |
+
atlassian-ide-plugin.xml
|
64 |
+
|
65 |
+
# Cursive Clojure plugin
|
66 |
+
.idea/replstate.xml
|
67 |
+
|
68 |
+
# SonarLint plugin
|
69 |
+
.idea/sonarlint/
|
70 |
+
|
71 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
72 |
+
com_crashlytics_export_strings.xml
|
73 |
+
crashlytics.properties
|
74 |
+
crashlytics-build.properties
|
75 |
+
fabric.properties
|
76 |
+
|
77 |
+
# Editor-based Rest Client
|
78 |
+
.idea/httpRequests
|
79 |
+
|
80 |
+
# Android studio 3.1+ serialized cache file
|
81 |
+
.idea/caches/build_file_checksums.ser
|
82 |
+
|
83 |
+
|
84 |
+
# VS Code Standard
|
85 |
+
.vscode/*
|
86 |
+
!.vscode/settings.json
|
87 |
+
!.vscode/tasks.json
|
88 |
+
!.vscode/launch.json
|
89 |
+
!.vscode/extensions.json
|
90 |
+
!.vscode/*.code-snippets
|
91 |
+
|
92 |
+
# Local History for Visual Studio Code
|
93 |
+
.history/
|
94 |
+
|
95 |
+
# Built Visual Studio Code Extensions
|
96 |
+
*.vsix
|
97 |
+
|
98 |
+
|
99 |
+
# Mac OS
|
100 |
+
# Source : https://raw.githubusercontent.com/github/gitignore/main/Global/macOS.gitignore
|
101 |
+
# General
|
102 |
+
.DS_Store
|
103 |
+
.AppleDouble
|
104 |
+
.LSOverride
|
105 |
+
|
106 |
+
# Icon must end with two \r
|
107 |
+
Icon
|
108 |
+
|
109 |
+
|
110 |
+
# Thumbnails
|
111 |
+
._*
|
112 |
+
|
113 |
+
# Files that might appear in the root of a volume
|
114 |
+
.DocumentRevisions-V100
|
115 |
+
.fseventsd
|
116 |
+
.Spotlight-V100
|
117 |
+
.TemporaryItems
|
118 |
+
.Trashes
|
119 |
+
.VolumeIcon.icns
|
120 |
+
.com.apple.timemachine.donotpresent
|
121 |
+
|
122 |
+
# Directories potentially created on remote AFP share
|
123 |
+
.AppleDB
|
124 |
+
.AppleDesktop
|
125 |
+
Network Trash Folder
|
126 |
+
Temporary Items
|
127 |
+
.apdisk
|
128 |
+
|
129 |
+
# Windows
|
130 |
+
# Source: https://raw.githubusercontent.com/github/gitignore/main/Global/Windows.gitignore
|
131 |
+
# Windows thumbnail cache files
|
132 |
+
Thumbs.db
|
133 |
+
Thumbs.db:encryptable
|
134 |
+
ehthumbs.db
|
135 |
+
ehthumbs_vista.db
|
136 |
+
|
137 |
+
# Dump file
|
138 |
+
*.stackdump
|
139 |
+
|
140 |
+
# Folder config file
|
141 |
+
[Dd]esktop.ini
|
142 |
+
|
143 |
+
# Recycle Bin used on file shares
|
144 |
+
$RECYCLE.BIN/
|
145 |
+
|
146 |
+
# Windows Installer files
|
147 |
+
*.cab
|
148 |
+
*.msi
|
149 |
+
*.msix
|
150 |
+
*.msm
|
151 |
+
*.msp
|
152 |
+
|
153 |
+
# Windows shortcuts
|
154 |
+
*.lnk
|
155 |
+
|
156 |
+
# Linux
|
157 |
+
# Source: https://raw.githubusercontent.com/github/gitignore/main/Global/Linux.gitignore
|
158 |
+
*~
|
159 |
+
|
160 |
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
161 |
+
.fuse_hidden*
|
162 |
+
|
163 |
+
# KDE directory preferences
|
164 |
+
.directory
|
165 |
+
|
166 |
+
# Linux trash folder which might appear on any partition or disk
|
167 |
+
.Trash-*
|
168 |
+
|
169 |
+
# .nfs files are created when an open file is removed but is still being accessed
|
170 |
+
.nfs*
|
171 |
+
|
172 |
+
__pycache__/
|
173 |
+
env/
|
COLLABORATORS
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Vy Nguyen - Github Username: vynpt
|
2 |
+
Andy Yang - Github Username: ayang903
|
3 |
+
Gauri Bhandarwar - Github Username: gbhandarwar
|
4 |
+
Weining Mai - Github Username: weibb123
|
Deployment/readme.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Demo app: https://maple-billsummarization.streamlit.app/
|
Documentation/Documentation for MAPLE.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6668bf5eb5b8f1f12b97e4a8a9d233fb56fb9820c0335f8f2ed14490d43b9c8b
|
3 |
+
size 4408831
|
Documentation/Research.md
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Research MAPLE
|
2 |
+
|
3 |
+
**Research Methods (MAPLE Project)**
|
4 |
+
|
5 |
+
**Team members:** Andy Yang, Gauri Bhandarwar, Weining Mai, Vy Nguyen
|
6 |
+
|
7 |
+
1. **Overview**
|
8 |
+
|
9 |
+
This paper goes over the methods for summarization and tagging of Massachusetts bills for the MAPLE Platform. The goal is to simplify the legal language and content to make it comprehensible for a broader audience (9th-grade comprehension level). This summarization has to be done while still retaining the key information about the bills and maintaining full accuracy. This involves utilizing Large Language Models (LLMs) to summarize and categorize the content effectively. This paper will summarize some of the methods, processes, considerations, and evaluation metrics used during our research process of finding the most suitable method to execute the project.
|
10 |
+
|
11 |
+
1. **Preliminary Research on LLMs and Performance Criteria Definition**
|
12 |
+
|
13 |
+
Before we dive into our research of LLMs we have defined a few criteria that will help us evaluate the models we are potentially using. These criteria and metrics are listed below:
|
14 |
+
|
15 |
+
- **Comprehensibility: Model's ability to generate text that is comprehensible (9th grade level)**
|
16 |
+
- **Content Accuracy: The model's ability to retain critical legal details and nuances in the summarization process.**
|
17 |
+
- **Scalability: The ability of the model to handle a large number of documents efficiently.**
|
18 |
+
- **Customizability: The ease with which the model can be fine-tuned or adapted to specific requirements of the task such as focusing on certain aspects of legal bills.**
|
19 |
+
- **Cost Efficiency: Considers the full expense of using the model including : training, fine-tuning, and runtime inference costs.**
|
20 |
+
- **Overall Suitability: A general suitability measure for the model, considering all the factors above.**
|
21 |
+
|
22 |
+
Based on these criteria and reading up on the various LLMs from different sites and papers (refer to sources), we have come up with a general table which contains all the models to whom we have assigned a high, medium or low grade for each of the criteria.
|
23 |
+
|
24 |
+
![alt text](https://lh7-us.googleusercontent.com/3dFnsfy5fdB-shdqnwpRB-Ol1rJ6QAbFrnUtGZ5J4hKMth8p4UlOvMui9Bo5qw5h-NEempkDnTNr3ma8xex4vCB2NzhzgfAYKo49h8pgK9BbcBttGFmQg12JPi6299D4BPXweCmNxiTjlMPjnzQgo1w)
|
25 |
+
|
26 |
+
**Figure 1** : Comparison of LLMs and methods based on key evaluation metrics
|
27 |
+
|
28 |
+
Above we have provided a succinct table generalizing the use-cases for each LLM / method based on criteria such as Comprehensibility, Content Accuracy, Scalability, Cost Efficiency, and given them a final sum of scores based on the factors that are most important for this project. These metrics will help us choose the best model for our application needs. Content Accuracy is one of the most important factors as we are dealing with legislation. This need for accuracy was also highlighted by the client as it is imperative for the summaries to be accurate to maintain the trustworthiness of the MAPLE platform.
|
29 |
+
|
30 |
+
In addition to that, comprehensibility is a close second however not as important because we can hopefully tune each model to summarize in a more simple manner. Due to the fact that cost is also another consideration, we have given High scores to BERT, T5, and GPT-3.5. However, we have not tested how far tuning some models like LLAMA and customized transformers can go yet. Regarding the Customizability criteria, LLAMA, T5, and Customer Training with Transformation models seem to offer high customizability as they can be fine-tuned for specific tasks and domains. Moreover, GPT-3.5, LLAMA, and T5 are moderately cost-efficient, considering their performance while XLNet, BERT, and Customer Training with Transformation might be costlier due to resource-intensive fine-tuning and training processes. We will also aditionally explore using GPT-4 and GPT-3.5 Turbo given the new OpenAI updates.
|
31 |
+
|
32 |
+
Overall, LLAMA, T5, and Customer Training with Transformer models appear to be the most suitable choices for simplifying Massachusetts bills since they excel in comprehensibility, content accuracy, customizability, and overall performance. Hence, we will put more emphasis on these models while conducting performance tests and cost analysis.
|
33 |
+
|
34 |
+
1. **Preliminary Testing**
|
35 |
+
|
36 |
+
![alt text](https://lh7-us.googleusercontent.com/se1QGXdHkGWoeaHh9Rpb9ow5zMnrWx4a83BVUXXGcStAfK4ni83xDTmnkuvk22E8CHJnO87aEYsSXScpc2ExcErr9xcQqPlH592iLX4vsKSb9g1bSM2h646F2w-UdvXEWMo7Wo0jR6DRgipbZvb7Q6U)
|
37 |
+
|
38 |
+
**Figure 2:** Rough Sketch of Development Process
|
39 |
+
|
40 |
+
![alt text](https://lh7-us.googleusercontent.com/_w1LP_RRoSIny-A-yS-d8C4RMyAZgDnr_TS1ny_a22vI3Giml-Rhm1kOaHA_ZxNjjUavWom3T9NJFMR6ORlfX_bop86Q6BN-xq_gUvxBnV47eX_rXuRxoU9kIuVfFw-I5Ru0sHW9wyUgEOLVRHw7ALg)
|
41 |
+
|
42 |
+
**Figure 3** : Scraping, Summarizing and tagging bills with a sample set of 10 bills
|
43 |
+
|
44 |
+
We were able to successfully use the API to retrieve key data for ten bills including the : Title, Bill Number, Docket Number, General Court Number and Document Text. We mainly used the document text and title, feeding it through GPT-3.5 to create a Web-app (see Appendix) to demonstrate the summaries that were outputted. We generated summaries based on their degree of comprehensibility – Kid level, College level and Professional (legal) level. For each bill in our sample set, we generated 3 types of summaries and evaluated them.
|
45 |
+
|
46 |
+
Right now we’re using ten bills for testing. We can pull all 6.5k bills using the /Documents endpoint, then passing each BillNumber into the /Documents/{document_number} endpoint. The final goal here would be a csv of bills, with different features so that we can do EDA and eventually use to feed into our models.
|
47 |
+
|
48 |
+
|
49 |
+
We noticed that in most of the bills the models were just summarizing the bills vaguely and not including important details such as the main amendment the bill was making, the sector the bill was affecting (ex:Automotive industry, Home, etc), the city or town the bill is affecting and other important information. In addition to that, we noticed that as we decreased the degree (College level to Kid level), the model got less specific and gave more vague summaries that did not relate to the specific key point of the bill but talked more about the general issue that it was tackling. As to improve, we will experiment with more prompts making sure summaries can capture main ideas. For example, we can give a large language model a persona or a role such as attorney and be specific on the requirements.
|
50 |
+
|
51 |
+
1. **Research Methods/tools for Improvement and Evaluation of Summaries**
|
52 |
+
|
53 |
+
We have included the summary of one interesting research paper that has to deal with the evaluation of the quality of summaries based on a method that relies on reference summaries created by humans.
|
54 |
+
|
55 |
+
**"ROUGE: A Package for Automatic Evaluation of Summaries" by Chin-Yew Lin:**
|
56 |
+
|
57 |
+
Link : [https://aclanthology.org/W04-1013.pdf](https://aclanthology.org/W04-1013.pdf)
|
58 |
+
|
59 |
+
(Summary of Paper Generated by SciSummary Tool)
|
60 |
+
|
61 |
+
This paper introduces ROUGE (Recall-Oriented Understudy for Gisting Evaluation), a toolkit used for the evaluation of automatic summarization and machine translation software. The focus of ROUGE is to determine the quality of summaries by comparing them to reference summaries created by humans (usually professional abstractors). The paper emphasizes the importance of recall in summary evaluation, considering the coverage of information as critical.
|
62 |
+
|
63 |
+
ROUGE employs various metrics, including ROUGE-N (overlap of N-grams between the system and reference summaries), ROUGE-L (longest common subsequence), ROUGE-W (weighted longest common subsequence), and others. These metrics provide different perspectives for assessing the content similarity between generated and reference summaries. Experiments using ROUGE on different summarization tasks have demonstrated its efficacy and correlation with human judgments, validating its utility as an automatic evaluation method for various kinds of summaries (extractive, abstractive, single-document, or multi-document). The paper concludes that ROUGE is a valuable, scalable, and reliable tool in the development and assessment cycle of automatic summarization systems.
|
64 |
+
|
65 |
+
**V. Conclusion**
|
66 |
+
|
67 |
+
Based off of our current findings and knowledge, we have one major takeaway which is to drive focus towards generating summaries that have the key important details such as the main amend the bill was making, the sector the bill was affecting (ex:Automotive industry, Home, etc), the city or town the bill is affecting and other important information. We hope to research more evaluation methods and techniques that will help us achieve this goal in the context of legal documents.
|
68 |
+
|
69 |
+
**Works Cited / Sources / Appendix**
|
70 |
+
|
71 |
+
**Sources for :** Figure 1 : Comparison of LLMs and methods based on key evaluation metrics (Numbered 1-11 as shown on Figure 1)
|
72 |
+
|
73 |
+
1. Brown, T. B., et al. (2020). Language Models are Few-Shot Learners. OpenAI Blog. Link: [https://arxiv.org/abs/2005.14165](https://arxiv.org/abs/2005.14165)
|
74 |
+
2. OpenAI API Documentation. Link: [https://beta.openai.com/docs/](https://beta.openai.com/docs/)
|
75 |
+
3. Yang, Z., et al. (2019). XLNet: Generalized Autoregressive Pretraining for Language Understanding. Link: [https://arxiv.org/abs/1906.08237](https://arxiv.org/abs/1906.08237)
|
76 |
+
4. XLNet Documentation, Hugging Face. Link: [https://huggingface.co/transformers/model_doc/xlnet.html](https://huggingface.co/transformers/model_doc/xlnet.html)
|
77 |
+
5. LLAMA: A Multi-Task Meta Learning Approach for Few-Shot Classification, 2021. Link: [https://arxiv.org/abs/2112.01547](https://arxiv.org/abs/2112.01547)
|
78 |
+
6. Devlin, J., et al. (2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. Link: [https://arxiv.org/abs/1810.04805](https://arxiv.org/abs/1810.04805)
|
79 |
+
7. BERT Documentation, Hugging Face. Link: [https://huggingface.co/transformers/model_doc/bert.html](https://huggingface.co/transformers/model_doc/bert.html)
|
80 |
+
8. Raffel, C., et al. (2019). Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer. Link: [https://arxiv.org/abs/1910.10683](https://arxiv.org/abs/1910.10683)
|
81 |
+
9. T5 Documentation, Hugging Face. Link: [https://huggingface.co/transformers/model_doc/t5.html](https://huggingface.co/transformers/model_doc/t5.html)
|
82 |
+
10. Vaswani, A., et al. (2017). Attention Is All You Need. Link: [https://arxiv.org/abs/1706.03762](https://arxiv.org/abs/1706.03762)
|
83 |
+
11. Custom Training of Transformers, Hugging Face. Link:[https://huggingface.co/transformers/custom_datasets.html](https://huggingface.co/transformers/custom_datasets.html)
|
84 |
+
|
85 |
+
**More Article Sources for LLMs + Implementation methods:**
|
86 |
+
|
87 |
+
[https://medium.com/analytics-vidhya/text-summarization-using-bert-gpt2-xlnet-5ee80608e961](https://medium.com/analytics-vidhya/text-summarization-using-bert-gpt2-xlnet-5ee80608e961)
|
88 |
+
|
89 |
+
[https://medium.com/@ps.augereau/the-power-of-named-entity-recognition-ner-with-llm-2ff413360c5#:~:text=It%20refers%20to%20the%20method,understanding%20and%20analyzing%20text%20data](https://medium.com/@ps.augereau/the-power-of-named-entity-recognition-ner-with-llm-2ff413360c5#:~:text=It%20refers%20to%20the%20method,understanding%20and%20analyzing%20text%20data).
|
90 |
+
|
91 |
+
**Appendix**
|
92 |
+
|
93 |
+
GPT 3.5 Web app Demo screenshot
|
94 |
+
|
95 |
+
![alt text](https://lh7-us.googleusercontent.com/VSlaYRa6BNNDIczT_O54r43UPZYhbvMpA0y_jcaqnHKd22HSCpxxfmJKntk3rliGoTZgZqfNZVnn1gMBuQH1ob1OC3k4l_ZcY5ZS3lCmVxTkX7CpO3Jhpc0jnGkaZeCOaGSevud1zaSjKfisAKoNxVk)
|
96 |
+
|
97 |
+
![alt text](https://lh7-us.googleusercontent.com/Ps0_uWz9BCgyWSRtfZTBJWyATV5fUcRAJaANSqWDQfKNWib3sI6zKqMZ21zkU-YJbPFIQOJrYqQptJAljuEfHpGoJBxoiJzTNkmmqha-z-3Y6YJIA2iwZXfnQfDSCFHpw-t1fcgCkhWYV_OeVchhHrU)
|
EDA/bills_topics.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
EDA/eda.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
EDA/primary_sponsor.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
EDA/top2vec.ipynb
ADDED
@@ -0,0 +1,582 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": []
|
7 |
+
},
|
8 |
+
"kernelspec": {
|
9 |
+
"name": "python3",
|
10 |
+
"display_name": "Python 3"
|
11 |
+
},
|
12 |
+
"language_info": {
|
13 |
+
"name": "python"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"cells": [
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"execution_count": null,
|
20 |
+
"metadata": {
|
21 |
+
"colab": {
|
22 |
+
"base_uri": "https://localhost:8080/"
|
23 |
+
},
|
24 |
+
"id": "BlYwantP4fpF",
|
25 |
+
"outputId": "32e70ec1-c239-452f-8cb2-c6646522ac62"
|
26 |
+
},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"output_type": "stream",
|
30 |
+
"name": "stdout",
|
31 |
+
"text": [
|
32 |
+
"Collecting top2vec\n",
|
33 |
+
" Downloading top2vec-1.0.29-py3-none-any.whl (26 kB)\n",
|
34 |
+
"Requirement already satisfied: numpy>=1.20.0 in /usr/local/lib/python3.10/dist-packages (from top2vec) (1.23.5)\n",
|
35 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from top2vec) (1.5.3)\n",
|
36 |
+
"Requirement already satisfied: scikit-learn>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from top2vec) (1.2.2)\n",
|
37 |
+
"Requirement already satisfied: gensim>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from top2vec) (4.3.2)\n",
|
38 |
+
"Collecting umap-learn>=0.5.1 (from top2vec)\n",
|
39 |
+
" Downloading umap-learn-0.5.4.tar.gz (90 kB)\n",
|
40 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m90.8/90.8 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
41 |
+
"\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
42 |
+
"Collecting hdbscan>=0.8.27 (from top2vec)\n",
|
43 |
+
" Downloading hdbscan-0.8.33.tar.gz (5.2 MB)\n",
|
44 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.2/5.2 MB\u001b[0m \u001b[31m53.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
45 |
+
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
|
46 |
+
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
|
47 |
+
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
48 |
+
"Requirement already satisfied: wordcloud in /usr/local/lib/python3.10/dist-packages (from top2vec) (1.9.2)\n",
|
49 |
+
"Requirement already satisfied: scipy>=1.7.0 in /usr/local/lib/python3.10/dist-packages (from gensim>=4.0.0->top2vec) (1.11.3)\n",
|
50 |
+
"Requirement already satisfied: smart-open>=1.8.1 in /usr/local/lib/python3.10/dist-packages (from gensim>=4.0.0->top2vec) (6.4.0)\n",
|
51 |
+
"Collecting cython<3,>=0.27 (from hdbscan>=0.8.27->top2vec)\n",
|
52 |
+
" Using cached Cython-0.29.36-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (1.9 MB)\n",
|
53 |
+
"Requirement already satisfied: joblib>=1.0 in /usr/local/lib/python3.10/dist-packages (from hdbscan>=0.8.27->top2vec) (1.3.2)\n",
|
54 |
+
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.2.0->top2vec) (3.2.0)\n",
|
55 |
+
"Requirement already satisfied: numba>=0.51.2 in /usr/local/lib/python3.10/dist-packages (from umap-learn>=0.5.1->top2vec) (0.56.4)\n",
|
56 |
+
"Collecting pynndescent>=0.5 (from umap-learn>=0.5.1->top2vec)\n",
|
57 |
+
" Downloading pynndescent-0.5.10.tar.gz (1.1 MB)\n",
|
58 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m45.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
59 |
+
"\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
60 |
+
"Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from umap-learn>=0.5.1->top2vec) (4.66.1)\n",
|
61 |
+
"Requirement already satisfied: tbb>=2019.0 in /usr/local/lib/python3.10/dist-packages (from umap-learn>=0.5.1->top2vec) (2021.10.0)\n",
|
62 |
+
"Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->top2vec) (2.8.2)\n",
|
63 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->top2vec) (2023.3.post1)\n",
|
64 |
+
"Requirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from wordcloud->top2vec) (9.4.0)\n",
|
65 |
+
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from wordcloud->top2vec) (3.7.1)\n",
|
66 |
+
"Requirement already satisfied: llvmlite<0.40,>=0.39.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba>=0.51.2->umap-learn>=0.5.1->top2vec) (0.39.1)\n",
|
67 |
+
"Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from numba>=0.51.2->umap-learn>=0.5.1->top2vec) (67.7.2)\n",
|
68 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas->top2vec) (1.16.0)\n",
|
69 |
+
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (1.1.1)\n",
|
70 |
+
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (0.12.1)\n",
|
71 |
+
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (4.43.1)\n",
|
72 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (1.4.5)\n",
|
73 |
+
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (23.2)\n",
|
74 |
+
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->wordcloud->top2vec) (3.1.1)\n",
|
75 |
+
"Building wheels for collected packages: hdbscan, umap-learn, pynndescent\n",
|
76 |
+
" Building wheel for hdbscan (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
77 |
+
" Created wheel for hdbscan: filename=hdbscan-0.8.33-cp310-cp310-linux_x86_64.whl size=3039150 sha256=9f003292f1f8cb7ad7c75405b0ae9c5dd34781ed3d3e84b67c79cbb555901c90\n",
|
78 |
+
" Stored in directory: /root/.cache/pip/wheels/75/0b/3b/dc4f60b7cc455efaefb62883a7483e76f09d06ca81cf87d610\n",
|
79 |
+
" Building wheel for umap-learn (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
80 |
+
" Created wheel for umap-learn: filename=umap_learn-0.5.4-py3-none-any.whl size=86770 sha256=32645d482bfb04f8b261441c153ed2211fcacdb89e09dd301d22767f4bb4e117\n",
|
81 |
+
" Stored in directory: /root/.cache/pip/wheels/fb/66/29/199acf5784d0f7b8add6d466175ab45506c96e386ed5dd0633\n",
|
82 |
+
" Building wheel for pynndescent (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
83 |
+
" Created wheel for pynndescent: filename=pynndescent-0.5.10-py3-none-any.whl size=55615 sha256=34156dbda65a71550da9cc4bf7d24d226a288d55fc81e4d3db3a8a182871d238\n",
|
84 |
+
" Stored in directory: /root/.cache/pip/wheels/4a/38/5d/f60a40a66a9512b7e5e83517ebc2d1b42d857be97d135f1096\n",
|
85 |
+
"Successfully built hdbscan umap-learn pynndescent\n",
|
86 |
+
"Installing collected packages: cython, pynndescent, hdbscan, umap-learn, top2vec\n",
|
87 |
+
" Attempting uninstall: cython\n",
|
88 |
+
" Found existing installation: Cython 3.0.4\n",
|
89 |
+
" Uninstalling Cython-3.0.4:\n",
|
90 |
+
" Successfully uninstalled Cython-3.0.4\n",
|
91 |
+
"Successfully installed cython-0.29.36 hdbscan-0.8.33 pynndescent-0.5.10 top2vec-1.0.29 umap-learn-0.5.4\n"
|
92 |
+
]
|
93 |
+
}
|
94 |
+
],
|
95 |
+
"source": [
|
96 |
+
"!pip install top2vec"
|
97 |
+
]
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"cell_type": "code",
|
101 |
+
"source": [
|
102 |
+
"import pandas as pd\n",
|
103 |
+
"from top2vec import Top2Vec\n",
|
104 |
+
"import nltk\n",
|
105 |
+
"import re"
|
106 |
+
],
|
107 |
+
"metadata": {
|
108 |
+
"id": "PnJXA9RQ9ACj"
|
109 |
+
},
|
110 |
+
"execution_count": null,
|
111 |
+
"outputs": []
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"cell_type": "code",
|
115 |
+
"source": [
|
116 |
+
"df = pd.read_csv('all_bills.csv')"
|
117 |
+
],
|
118 |
+
"metadata": {
|
119 |
+
"id": "ei_AkGL74iks"
|
120 |
+
},
|
121 |
+
"execution_count": null,
|
122 |
+
"outputs": []
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"cell_type": "code",
|
126 |
+
"source": [
|
127 |
+
"df['DocumentText']"
|
128 |
+
],
|
129 |
+
"metadata": {
|
130 |
+
"colab": {
|
131 |
+
"base_uri": "https://localhost:8080/"
|
132 |
+
},
|
133 |
+
"id": "g9VfgRw9PDgQ",
|
134 |
+
"outputId": "6df29022-8d82-4fb2-9d4a-03bf045d9022"
|
135 |
+
},
|
136 |
+
"execution_count": null,
|
137 |
+
"outputs": [
|
138 |
+
{
|
139 |
+
"output_type": "execute_result",
|
140 |
+
"data": {
|
141 |
+
"text/plain": [
|
142 |
+
"0 NaN\n",
|
143 |
+
"1 \\tParagraph (c) of Section 91 of chapter 32 of...\n",
|
144 |
+
"2 \\tSECTION 1. Chapter 20 Section 23 of the Gene...\n",
|
145 |
+
"3 \\tSECTION 1. Chapter 26 of the General Laws is...\n",
|
146 |
+
"4 \\tSECTION 1. Chapter 32A of the General Laws i...\n",
|
147 |
+
" ... \n",
|
148 |
+
"6591 \\tSECTION 1. Section 3 of chapter 258B, as app...\n",
|
149 |
+
"6592 \\tSECTION 1. Section 222 of chapter 6 of the G...\n",
|
150 |
+
"6593 \\tSECTION 1. Chapter 12 of the General Laws, a...\n",
|
151 |
+
"6594 \\tSECTION 1. Section 172(a)(3) of chapter 6, a...\n",
|
152 |
+
"6595 \\tSection 127I of Chapter 111 of the General L...\n",
|
153 |
+
"Name: DocumentText, Length: 6596, dtype: object"
|
154 |
+
]
|
155 |
+
},
|
156 |
+
"metadata": {},
|
157 |
+
"execution_count": 7
|
158 |
+
}
|
159 |
+
]
|
160 |
+
},
|
161 |
+
{
|
162 |
+
"cell_type": "code",
|
163 |
+
"source": [
|
164 |
+
"nltk.download('punkt')"
|
165 |
+
],
|
166 |
+
"metadata": {
|
167 |
+
"colab": {
|
168 |
+
"base_uri": "https://localhost:8080/"
|
169 |
+
},
|
170 |
+
"id": "rM2quh8P9Q8p",
|
171 |
+
"outputId": "c9d4dfe6-3bc4-4b17-f955-b41c59f4ce7e"
|
172 |
+
},
|
173 |
+
"execution_count": null,
|
174 |
+
"outputs": [
|
175 |
+
{
|
176 |
+
"output_type": "stream",
|
177 |
+
"name": "stderr",
|
178 |
+
"text": [
|
179 |
+
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
|
180 |
+
"[nltk_data] Unzipping tokenizers/punkt.zip.\n"
|
181 |
+
]
|
182 |
+
},
|
183 |
+
{
|
184 |
+
"output_type": "execute_result",
|
185 |
+
"data": {
|
186 |
+
"text/plain": [
|
187 |
+
"True"
|
188 |
+
]
|
189 |
+
},
|
190 |
+
"metadata": {},
|
191 |
+
"execution_count": 5
|
192 |
+
}
|
193 |
+
]
|
194 |
+
},
|
195 |
+
{
|
196 |
+
"cell_type": "code",
|
197 |
+
"source": [
|
198 |
+
"documents = df['DocumentText'].tolist()"
|
199 |
+
],
|
200 |
+
"metadata": {
|
201 |
+
"id": "5AJtHmk35Pjz"
|
202 |
+
},
|
203 |
+
"execution_count": null,
|
204 |
+
"outputs": []
|
205 |
+
},
|
206 |
+
{
|
207 |
+
"cell_type": "code",
|
208 |
+
"source": [
|
209 |
+
"from nltk.corpus import stopwords\n",
|
210 |
+
"\n",
|
211 |
+
"nltk.download('stopwords')\n",
|
212 |
+
"stop_words = set(stopwords.words('english'))"
|
213 |
+
],
|
214 |
+
"metadata": {
|
215 |
+
"colab": {
|
216 |
+
"base_uri": "https://localhost:8080/"
|
217 |
+
},
|
218 |
+
"id": "_woW4lDxPTa1",
|
219 |
+
"outputId": "6dbebac9-3dc8-420c-abf0-d1978b9e978a"
|
220 |
+
},
|
221 |
+
"execution_count": null,
|
222 |
+
"outputs": [
|
223 |
+
{
|
224 |
+
"output_type": "stream",
|
225 |
+
"name": "stderr",
|
226 |
+
"text": [
|
227 |
+
"[nltk_data] Downloading package stopwords to /root/nltk_data...\n",
|
228 |
+
"[nltk_data] Package stopwords is already up-to-date!\n"
|
229 |
+
]
|
230 |
+
}
|
231 |
+
]
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"cell_type": "code",
|
235 |
+
"source": [
|
236 |
+
"def tokenize(text):\n",
|
237 |
+
" if not isinstance(text, str): # Check if the input is a string, could be null\n",
|
238 |
+
" return []\n",
|
239 |
+
"\n",
|
240 |
+
" wordstoremove = []\n",
|
241 |
+
"\n",
|
242 |
+
" all_stopwords = stop_words.union(wordstoremove) # remove stopwords\n",
|
243 |
+
"\n",
|
244 |
+
" text = re.sub(r'(section|chapter)\\s+(\\d+|\\d+[a-zA-Z])', r'\\1_\\2', text, flags=re.IGNORECASE) #combine \"section\" and \"chapter\" followed by a number into one token\n",
|
245 |
+
"\n",
|
246 |
+
" tokens = [word for word in nltk.word_tokenize(text) if word.lower() not in all_stopwords and word.isalnum()] #only alphanumeric\n",
|
247 |
+
" tokens = map(str.lower, tokens)\n",
|
248 |
+
"\n",
|
249 |
+
" return tokens\n",
|
250 |
+
"\n",
|
251 |
+
"tokenized_documents = [\" \".join(tokenize(doc)) for doc in documents]\n"
|
252 |
+
],
|
253 |
+
"metadata": {
|
254 |
+
"id": "W9_54EGS9W8C"
|
255 |
+
},
|
256 |
+
"execution_count": null,
|
257 |
+
"outputs": []
|
258 |
+
},
|
259 |
+
{
|
260 |
+
"cell_type": "code",
|
261 |
+
"source": [
|
262 |
+
"len(tokenized_documents)"
|
263 |
+
],
|
264 |
+
"metadata": {
|
265 |
+
"colab": {
|
266 |
+
"base_uri": "https://localhost:8080/"
|
267 |
+
},
|
268 |
+
"id": "cne6GU2k6OJI",
|
269 |
+
"outputId": "b2a8a635-f35c-436c-a899-dd52d10b3199"
|
270 |
+
},
|
271 |
+
"execution_count": null,
|
272 |
+
"outputs": [
|
273 |
+
{
|
274 |
+
"output_type": "execute_result",
|
275 |
+
"data": {
|
276 |
+
"text/plain": [
|
277 |
+
"6596"
|
278 |
+
]
|
279 |
+
},
|
280 |
+
"metadata": {},
|
281 |
+
"execution_count": 28
|
282 |
+
}
|
283 |
+
]
|
284 |
+
},
|
285 |
+
{
|
286 |
+
"cell_type": "code",
|
287 |
+
"source": [
|
288 |
+
"\n",
|
289 |
+
"tokenized_documents[5]"
|
290 |
+
],
|
291 |
+
"metadata": {
|
292 |
+
"colab": {
|
293 |
+
"base_uri": "https://localhost:8080/",
|
294 |
+
"height": 160
|
295 |
+
},
|
296 |
+
"id": "E7FVyM1bSySo",
|
297 |
+
"outputId": "023d7323-6202-4703-a3d3-632edcee0ce0"
|
298 |
+
},
|
299 |
+
"execution_count": null,
|
300 |
+
"outputs": [
|
301 |
+
{
|
302 |
+
"output_type": "execute_result",
|
303 |
+
"data": {
|
304 |
+
"text/plain": [
|
305 |
+
"'general laws appearing 2020 official edition hereby amended striking first sentence second paragraph inserting words commission shall provide child adult 26 years age younger active retired employee commonwealth insured group insurance commission coverage cost 1 hearing aid per ear hearing aid defined every 36 months upon written statement child treating physician hearing aids necessary regardless etiology general laws appearing 2020 official edition hereby amended striking first sentence second paragraph inserting words individual group health maintenance contract except contracts providing supplemental coverage medicare governmental programs shall provide coverage benefits children 21 years age younger insured contracts expenses incurred cost 1 hearing aid per hearing impaired ear hearing aid defined every 36 months upon written statement child treating physician hearing aids necessary regardless etiology'"
|
306 |
+
],
|
307 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
308 |
+
"type": "string"
|
309 |
+
}
|
310 |
+
},
|
311 |
+
"metadata": {},
|
312 |
+
"execution_count": 31
|
313 |
+
}
|
314 |
+
]
|
315 |
+
},
|
316 |
+
{
|
317 |
+
"cell_type": "code",
|
318 |
+
"source": [
|
319 |
+
"model = Top2Vec(tokenized_documents)"
|
320 |
+
],
|
321 |
+
"metadata": {
|
322 |
+
"colab": {
|
323 |
+
"base_uri": "https://localhost:8080/"
|
324 |
+
},
|
325 |
+
"id": "WcNxyEeA4_Al",
|
326 |
+
"outputId": "da47e569-f7b1-4370-dfe0-e44a7a5295b3"
|
327 |
+
},
|
328 |
+
"execution_count": null,
|
329 |
+
"outputs": [
|
330 |
+
{
|
331 |
+
"output_type": "stream",
|
332 |
+
"name": "stderr",
|
333 |
+
"text": [
|
334 |
+
"2023-10-26 18:48:40,257 - top2vec - INFO - Pre-processing documents for training\n",
|
335 |
+
"INFO:top2vec:Pre-processing documents for training\n",
|
336 |
+
"2023-10-26 18:48:50,371 - top2vec - INFO - Creating joint document/word embedding\n",
|
337 |
+
"INFO:top2vec:Creating joint document/word embedding\n",
|
338 |
+
"2023-10-26 19:01:10,148 - top2vec - INFO - Creating lower dimension embedding of documents\n",
|
339 |
+
"INFO:top2vec:Creating lower dimension embedding of documents\n",
|
340 |
+
"2023-10-26 19:01:54,142 - top2vec - INFO - Finding dense areas of documents\n",
|
341 |
+
"INFO:top2vec:Finding dense areas of documents\n",
|
342 |
+
"2023-10-26 19:01:54,586 - top2vec - INFO - Finding topics\n",
|
343 |
+
"INFO:top2vec:Finding topics\n"
|
344 |
+
]
|
345 |
+
}
|
346 |
+
]
|
347 |
+
},
|
348 |
+
{
|
349 |
+
"cell_type": "code",
|
350 |
+
"source": [
|
351 |
+
"# 86 topics found\n",
|
352 |
+
"model.get_num_topics()"
|
353 |
+
],
|
354 |
+
"metadata": {
|
355 |
+
"colab": {
|
356 |
+
"base_uri": "https://localhost:8080/"
|
357 |
+
},
|
358 |
+
"id": "f6K7dLRr5HzO",
|
359 |
+
"outputId": "ad6600c3-f4c2-49c9-8340-5aa5cb45a634"
|
360 |
+
},
|
361 |
+
"execution_count": null,
|
362 |
+
"outputs": [
|
363 |
+
{
|
364 |
+
"output_type": "execute_result",
|
365 |
+
"data": {
|
366 |
+
"text/plain": [
|
367 |
+
"86"
|
368 |
+
]
|
369 |
+
},
|
370 |
+
"metadata": {},
|
371 |
+
"execution_count": 33
|
372 |
+
}
|
373 |
+
]
|
374 |
+
},
|
375 |
+
{
|
376 |
+
"cell_type": "code",
|
377 |
+
"source": [
|
378 |
+
"topic_sizes, topic_nums = model.get_topic_sizes()"
|
379 |
+
],
|
380 |
+
"metadata": {
|
381 |
+
"id": "nBOvsphU6TsK"
|
382 |
+
},
|
383 |
+
"execution_count": null,
|
384 |
+
"outputs": []
|
385 |
+
},
|
386 |
+
{
|
387 |
+
"cell_type": "code",
|
388 |
+
"source": [
|
389 |
+
"topic_sizes, topic_nums"
|
390 |
+
],
|
391 |
+
"metadata": {
|
392 |
+
"colab": {
|
393 |
+
"base_uri": "https://localhost:8080/"
|
394 |
+
},
|
395 |
+
"id": "_ficy58j6Val",
|
396 |
+
"outputId": "c3aa223b-78b8-4bec-a7d2-8419d038abd4"
|
397 |
+
},
|
398 |
+
"execution_count": null,
|
399 |
+
"outputs": [
|
400 |
+
{
|
401 |
+
"output_type": "execute_result",
|
402 |
+
"data": {
|
403 |
+
"text/plain": [
|
404 |
+
"(array([269, 222, 184, 179, 168, 161, 157, 149, 149, 144, 138, 128, 122,\n",
|
405 |
+
" 118, 105, 101, 97, 95, 95, 90, 90, 89, 88, 88, 84, 83,\n",
|
406 |
+
" 83, 80, 79, 77, 76, 75, 74, 73, 73, 73, 72, 71, 69,\n",
|
407 |
+
" 69, 69, 68, 66, 65, 65, 64, 64, 62, 62, 62, 61, 60,\n",
|
408 |
+
" 59, 55, 54, 53, 52, 50, 49, 49, 49, 48, 48, 48, 48,\n",
|
409 |
+
" 47, 46, 44, 44, 41, 40, 37, 37, 36, 36, 35, 35, 33,\n",
|
410 |
+
" 32, 30, 29, 29, 25, 25, 24, 24]),\n",
|
411 |
+
" array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
|
412 |
+
" 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n",
|
413 |
+
" 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,\n",
|
414 |
+
" 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,\n",
|
415 |
+
" 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,\n",
|
416 |
+
" 85]))"
|
417 |
+
]
|
418 |
+
},
|
419 |
+
"metadata": {},
|
420 |
+
"execution_count": 35
|
421 |
+
}
|
422 |
+
]
|
423 |
+
},
|
424 |
+
{
|
425 |
+
"cell_type": "code",
|
426 |
+
"source": [
|
427 |
+
"topic_words, word_scores, topic_nums = model.get_topics(86)\n"
|
428 |
+
],
|
429 |
+
"metadata": {
|
430 |
+
"id": "incHyPTC6Wky"
|
431 |
+
},
|
432 |
+
"execution_count": null,
|
433 |
+
"outputs": []
|
434 |
+
},
|
435 |
+
{
|
436 |
+
"cell_type": "code",
|
437 |
+
"source": [
|
438 |
+
"topic_words"
|
439 |
+
],
|
440 |
+
"metadata": {
|
441 |
+
"colab": {
|
442 |
+
"base_uri": "https://localhost:8080/"
|
443 |
+
},
|
444 |
+
"id": "z9iNedwx6bIO",
|
445 |
+
"outputId": "4b3ecf45-bfe7-4763-8360-ae52d75df083"
|
446 |
+
},
|
447 |
+
"execution_count": null,
|
448 |
+
"outputs": [
|
449 |
+
{
|
450 |
+
"output_type": "execute_result",
|
451 |
+
"data": {
|
452 |
+
"text/plain": [
|
453 |
+
"array([['senate', 'representatives', 'recommendations', ...,\n",
|
454 |
+
" 'massachusetts', 'member', 'vice'],\n",
|
455 |
+
" ['taxable', 'taxpayer', 'tax', ..., 'deducted', 'percent',\n",
|
456 |
+
" 'assessors'],\n",
|
457 |
+
" ['ballot', 'election', 'voters', ..., 'names', 'choice', 'papers'],\n",
|
458 |
+
" ...,\n",
|
459 |
+
" ['pesticide', 'pesticides', 'applicator', ..., 'contain',\n",
|
460 |
+
" 'application', 'polyfluoroalkyl'],\n",
|
461 |
+
" ['affordable', 'real', 'transfers', ..., 'respect', 'excise',\n",
|
462 |
+
" 'barnstable'],\n",
|
463 |
+
" ['detail', 'police', 'superannuation', ..., 'eeo', 'overtime',\n",
|
464 |
+
" 'passage']], dtype='<U15')"
|
465 |
+
]
|
466 |
+
},
|
467 |
+
"metadata": {},
|
468 |
+
"execution_count": 41
|
469 |
+
}
|
470 |
+
]
|
471 |
+
},
|
472 |
+
{
|
473 |
+
"cell_type": "code",
|
474 |
+
"source": [
|
475 |
+
"# example of a topic\n",
|
476 |
+
"topic_words[15]"
|
477 |
+
],
|
478 |
+
"metadata": {
|
479 |
+
"colab": {
|
480 |
+
"base_uri": "https://localhost:8080/"
|
481 |
+
},
|
482 |
+
"id": "2rnYtcMsXeFj",
|
483 |
+
"outputId": "8f52f099-c97a-4023-c003-d768ba546278"
|
484 |
+
},
|
485 |
+
"execution_count": null,
|
486 |
+
"outputs": [
|
487 |
+
{
|
488 |
+
"output_type": "execute_result",
|
489 |
+
"data": {
|
490 |
+
"text/plain": [
|
491 |
+
"array(['assessors', 'exemption', 'valuation', 'qualify', 'domicile',\n",
|
492 |
+
" 'exemptions', 'levy', 'taxes', 'taxation', 'real', 'occupied',\n",
|
493 |
+
" 'town', 'assessed', 'abatement', 'tax', 'deferral', 'city',\n",
|
494 |
+
" 'deadline', 'excessive', 'parcel', 'property', 'domiciled',\n",
|
495 |
+
" 'senior', 'surcharge', 'condominium', 'seeks', 'raised', 'estate',\n",
|
496 |
+
" 'clause', 'assessor', 'homeowners', 'voters', 'bears', 'income',\n",
|
497 |
+
" 'owned', 'shift', 'estates', 'residential', 'deed', 'filed',\n",
|
498 |
+
" 'eighteenth', 'lien', 'decedent', 'certifies', 'year', 'find',\n",
|
499 |
+
" 'qualifies', 'nonpayment', 'mayor', 'question'], dtype='<U15')"
|
500 |
+
]
|
501 |
+
},
|
502 |
+
"metadata": {},
|
503 |
+
"execution_count": 53
|
504 |
+
}
|
505 |
+
]
|
506 |
+
},
|
507 |
+
{
|
508 |
+
"cell_type": "code",
|
509 |
+
"source": [
|
510 |
+
"word_scores"
|
511 |
+
],
|
512 |
+
"metadata": {
|
513 |
+
"colab": {
|
514 |
+
"base_uri": "https://localhost:8080/"
|
515 |
+
},
|
516 |
+
"id": "z4l9d3jT6b7b",
|
517 |
+
"outputId": "f4f2a0f0-fd81-4da3-f4a8-6f3c00069e73"
|
518 |
+
},
|
519 |
+
"execution_count": null,
|
520 |
+
"outputs": [
|
521 |
+
{
|
522 |
+
"output_type": "execute_result",
|
523 |
+
"data": {
|
524 |
+
"text/plain": [
|
525 |
+
"array([[0.8107485 , 0.76834613, 0.75448215, 0.7522937 , 0.7377519 ,\n",
|
526 |
+
" 0.73589534, 0.6997856 , 0.6921088 , 0.6573265 , 0.63992095,\n",
|
527 |
+
" 0.63835424, 0.63353044, 0.6259784 , 0.6161628 , 0.6136363 ,\n",
|
528 |
+
" 0.61158836, 0.5917918 , 0.59075636, 0.58117676, 0.56409115,\n",
|
529 |
+
" 0.5382238 , 0.53799826, 0.53545713, 0.5059549 , 0.4826639 ,\n",
|
530 |
+
" 0.47157508, 0.47056037, 0.44637784, 0.42377606, 0.42022526,\n",
|
531 |
+
" 0.4182046 , 0.41616178, 0.41021925, 0.40735632, 0.38740572,\n",
|
532 |
+
" 0.3687165 , 0.36273247, 0.360592 , 0.3579704 , 0.35582146,\n",
|
533 |
+
" 0.35553864, 0.3502974 , 0.34837744, 0.34191263, 0.34068382,\n",
|
534 |
+
" 0.33285785, 0.3286861 , 0.30501026, 0.30333635, 0.29198554],\n",
|
535 |
+
" [0.6651959 , 0.65478694, 0.6534573 , 0.6209365 , 0.6145715 ,\n",
|
536 |
+
" 0.60944825, 0.578282 , 0.5713501 , 0.56624013, 0.5658411 ,\n",
|
537 |
+
" 0.5317777 , 0.5303422 , 0.52419686, 0.48169795, 0.47910136,\n",
|
538 |
+
" 0.4783927 , 0.46999556, 0.46702635, 0.45967853, 0.4526093 ,\n",
|
539 |
+
" 0.43824282, 0.4347589 , 0.43464437, 0.4327737 , 0.4292552 ,\n",
|
540 |
+
" 0.42650297, 0.42139018, 0.41712484, 0.4164454 , 0.40693063,\n",
|
541 |
+
" 0.3967685 , 0.3945102 , 0.39216924, 0.390456 , 0.39004803,\n",
|
542 |
+
" 0.37376937, 0.36957765, 0.3680184 , 0.36738494, 0.35837635,\n",
|
543 |
+
" 0.33738944, 0.3371164 , 0.33683145, 0.3082167 , 0.30309388,\n",
|
544 |
+
" 0.30301207, 0.28206518, 0.27416578, 0.2736898 , 0.27321362]],\n",
|
545 |
+
" dtype=float32)"
|
546 |
+
]
|
547 |
+
},
|
548 |
+
"metadata": {},
|
549 |
+
"execution_count": 40
|
550 |
+
}
|
551 |
+
]
|
552 |
+
},
|
553 |
+
{
|
554 |
+
"cell_type": "code",
|
555 |
+
"source": [
|
556 |
+
"def save_topics_to_txt(topic_words, word_scores, topic_nums, filename=\"bills_topics.txt\"):\n",
|
557 |
+
" with open(filename, 'w') as file:\n",
|
558 |
+
" for topic_num, words, scores in zip(topic_nums, topic_words, word_scores):\n",
|
559 |
+
" file.write(f\"Topic {topic_num}\\n\")\n",
|
560 |
+
" for word, score in zip(words, scores):\n",
|
561 |
+
" file.write(f\"{word}: {score}\\n\")\n",
|
562 |
+
" file.write(\"\\n\")\n",
|
563 |
+
"\n",
|
564 |
+
"save_topics_to_txt(topic_words, word_scores, topic_nums, filename=\"bills_topics.txt\")\n"
|
565 |
+
],
|
566 |
+
"metadata": {
|
567 |
+
"id": "2vKfMzeA667n"
|
568 |
+
},
|
569 |
+
"execution_count": null,
|
570 |
+
"outputs": []
|
571 |
+
},
|
572 |
+
{
|
573 |
+
"cell_type": "code",
|
574 |
+
"source": [],
|
575 |
+
"metadata": {
|
576 |
+
"id": "VbuUEU2OYlVW"
|
577 |
+
},
|
578 |
+
"execution_count": null,
|
579 |
+
"outputs": []
|
580 |
+
}
|
581 |
+
]
|
582 |
+
}
|
LICENSE
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
635 |
+
Copyright (C) <year> <name of author>
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
<program> Copyright (C) <year> <name of author>
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<https://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
Project_outline.md
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Maple-Bill Summarization and Tagging Project Document
|
2 |
+
|
3 |
+
## Vy Nguyen, Gauri Bhandarwar, Andy Yang, and Weining Mai *2023-October-05*
|
4 |
+
|
5 |
+
## Overview
|
6 |
+
|
7 |
+
*In this document, based on the available project outline and summary of the project pitch, to the best of your abilities, you will come up with the technical plan or goals for implementing the project such that it best meets the stakeholder requirements.*
|
8 |
+
|
9 |
+
### A. Provide a solution in terms of human actions to confirm if the task is within the scope of automation through AI.
|
10 |
+
|
11 |
+
*To assist in outlining the steps needed to achieve our final goal, outline the AI-less process that we are trying to automate with Machine Learning. Provide as much detail as possible.*
|
12 |
+
|
13 |
+
We are trying to automate the process of summarizing and tagging Massachusetts bills. For example, there are approximately thousands of bills here: [Links](https://malegislature.gov/Bills/Search)\
|
14 |
+
Our goal will be building a system that summarizes all of these bills into more digestible pieces of texts, as well as tagging each bill so that we can separate them into different categories.
|
15 |
+
|
16 |
+
### B. Problem Statement:
|
17 |
+
|
18 |
+
*In as direct terms as possible, provide the “Data Science” or "Machine Learning" problem statement version of the overview. Think of this as translating the above into a more technical definition to execute on. eg: a classification problem to segregate users into one of three groups on based on the historical user data available from a publicly available database*
|
19 |
+
|
20 |
+
A natural language generation problem to generate easy-understanding summaries and category tags for pending legislation based on the public data available from Massachusetts Legislature.
|
21 |
+
|
22 |
+
### C. Checklist for project completion
|
23 |
+
|
24 |
+
*Provide a bulleted list to the best of your current understanding, of the concrete technical goals and artifacts that, when complete, define the completion of the project. This checklist will likely evolve as your project progresses.*
|
25 |
+
|
26 |
+
1. Scrape bills, tagging
|
27 |
+
2. Data Preprocessing
|
28 |
+
3. Summarization and tagging
|
29 |
+
4. Deployment and automation
|
30 |
+
|
31 |
+
### D. Outline a path to operationalization.
|
32 |
+
|
33 |
+
We hope to have the generated summaries available in multiple formats either as csv or rich text. If time permits, it would be interesting to explore the output on a simple AI application power by Gradio or Streamlit so users can see generated summaries and tagging for the bills.
|
34 |
+
|
35 |
+
We hope to have the output available in multiple formats (csv, rich text, etc). If time permits it would be interesting to explore population of the output on the website itself and automate the process of summarization and tagging using something like Apache airflow.
|
36 |
+
|
37 |
+
## Resources
|
38 |
+
|
39 |
+
### Data Sets
|
40 |
+
|
41 |
+
- Collect bills from Massachusetts Legislature
|
42 |
+
|
43 |
+
https://malegislature.gov/Bills/Search
|
44 |
+
|
45 |
+
The /Documents endpoint provides a list of every single publicly available document with information like BillNumber, Title, GeneralCourtNumber, etc. We will use the "BillNumber" field with the /Documents/{document_number} endpoint to get the text for all the bills
|
46 |
+
|
47 |
+
API endpoint to get the BillNumbers: https://malegislature.gov/api/Documents
|
48 |
+
|
49 |
+
API endpoint to get the raw text: https://malegislature.gov/api/Documents/{document_number}
|
50 |
+
|
51 |
+
There are approximately 6595 bills, from the first endpoint.
|
52 |
+
|
53 |
+
- Massachusetts General Law sections and subsections as category tags
|
54 |
+
|
55 |
+
https://malegislature.gov/Laws/GeneralLaws
|
56 |
+
|
57 |
+
Tags in JSON found here: https://drive.google.com/drive/folders/1QVI6wbLREsU4jQ_llogiTKM0YgC_dqVL
|
58 |
+
|
59 |
+
- Additional information on this task (including examples)
|
60 |
+
|
61 |
+
https://github.com/codeforboston/maple/issues/843
|
62 |
+
|
63 |
+
- API:
|
64 |
+
https://malegislature.gov/api/swagger/index.html?url=/api/swagger/v1/swagger.json#/
|
65 |
+
|
66 |
+
|
67 |
+
### References
|
68 |
+
|
69 |
+
Armand Ruiz, AI director at IBM, for his helpful guides and blogs on Generative AI.
|
70 |
+
|
71 |
+
link: [nocode.ai](http://nocode.ai)
|
72 |
+
|
73 |
+
# Weekly Meeting Update
|
Prompts Engineering/prompts.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Prompt 1
|
2 |
+
Prompt1 =
|
3 |
+
""""I want you to act as a text summarizer and provide a concise summary of the bill separated by ####.
|
4 |
+
Summarize the text so {level} can understand Your summary should be no more than 4 sentences.
|
5 |
+
Do not include your opinions or interpretations and do not make up any false information.
|
6 |
+
Also, I want you to define the main topic for this bill For example, Topic: Bills about unjustice
|
7 |
+
|
8 |
+
s #### \
|
9 |
+
{context} \
|
10 |
+
s #### """
|
11 |
+
|
12 |
+
## Prompt 2
|
13 |
+
Prompt2 =
|
14 |
+
""""I want a summarizer that reads and summarizes legal bills and legislation. I want the summary to not be vague and include the general amendments, area the legislation is affecting, the purpose, the town/city it is affecting, etc. Based on the bill text {context} given please create a concise and easy-to-understand summary with the relevant key points.
|
15 |
+
"""
|
16 |
+
|
17 |
+
## Prompt 3
|
18 |
+
Prompt3 =
|
19 |
+
"""You are an experienced attorney in Massachusetts. Write a concise summary of the bill separated by #### so {level} can understand. Do not make up false information.
|
20 |
+
Include the general amendments, area the legislation is affecting, the purpose, the town and city it is affecting.
|
21 |
+
|
22 |
+
s #### \
|
23 |
+
{context} \
|
24 |
+
s #### """
|
25 |
+
|
26 |
+
## Prompt 4
|
27 |
+
template = """"Your task is to generate a concise summary of a bill
|
28 |
+
from massachusetts legislature. Make sure to capture the main idea of the bill.
|
29 |
+
|
30 |
+
Summarize the bill below, delimited by triple backticks, and summarize in a way so {level} can understand.
|
31 |
+
|
32 |
+
These are the informations
|
33 |
+
bill: ```{context}```
|
34 |
+
tags: #### {schema} ####
|
35 |
+
|
36 |
+
provide your summary in a consistent style
|
37 |
+
Summary: your summary
|
38 |
+
|
39 |
+
category: choose one category from the list of categories, delimited by ####, that is relevant to the summary
|
40 |
+
|
41 |
+
next, after you select a category, identify tags that are relevant to your summary.
|
42 |
+
Do not make up any false information.
|
43 |
+
|
44 |
+
"""
|
Prompts Engineering/readme.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Keep track of used prompts
|
README.md
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# MAPLE (Bill Summarization, Tagging, Explanation)
|
2 |
+
In this project, we generate summaries and category tags for of Massachusetts bills for [MAPLE Platform](https://www.mapletestimony.org/). The goal is to simplify the legal language and content to make it comprehensible for a broader audience (9th-grade comprehension level) by exploring different ML and LLM services.
|
3 |
+
|
4 |
+
This repository contains a pipeline from taking bills from Massachusetts legislature, generating summaries and category tags leveraging different the Massachusetts General Law sections, creating a dashboard to display and save the generated texts, to deploying and integrating into MAPLE platform.
|
5 |
+
|
6 |
+
## Roadmap of Repository Directories
|
7 |
+
* [Documentation](https://github.com/vynpt/ml-maple-bill-summarization/tree/dev/Documentation):
|
8 |
+
```Research.md```: our research on large language models and evaluation methods we planned to use for this project.
|
9 |
+
```Documentation MAPLE.pdf```: includes detail operation of our model for future use and improvement.
|
10 |
+
|
11 |
+
* [EDA](https://github.com/vynpt/ml-maple-bill-summarization/tree/dev/EDA): the notebook ```eda.ipynb``` includes our work from scraping data that takes bills from MAPLE Swagger API, creating a dataframe to clean and process data, making visualizations to analyze data and explore characteristics of the dataset.
|
12 |
+
|
13 |
+
* [demoapp](https://github.com/vynpt/ml-maple-bill-summarization/tree/dev/demoapp):
|
14 |
+
```app.py```: contains the codes of the LLM service we used and the wepapp we made using Streamlit. The webapp allows user to search for all bills.
|
15 |
+
```app2.py```: we test on top 12 bills from MAPLE website. We extract information from [Massachusetts General Law](https://malegislature.gov/Laws/GeneralLaws) to add context for the summaries of these bills.
|
16 |
+
Other files: helper files to be imported in the above two Python app files.
|
17 |
+
|
18 |
+
* [Prompts Engineering](https://github.com/vynpt/ml-maple-bill-summarization/tree/dev/Prompts%20Engineering): ```prompts.md``` stores all prompts that we tested.
|
19 |
+
|
20 |
+
* [Tagging](https://github.com/vynpt/ml-maple-bill-summarization/tree/dev/Tagging): contains the list of categories and tags.
|
21 |
+
|
22 |
+
* [Deployment](https://github.com/vynpt/ml-maple-bill-summarization/tree/main/Deployment): contains the link of our Streamlit deployed webapp.
|
23 |
+
|
24 |
+
## Ethical Implications
|
25 |
+
The dataset used for this project is fully open sourced and can be access through Mass General Laws API.
|
26 |
+
|
27 |
+
Our team and MAPLE agree about putting disclaimer that this text is AI-generated.
|
28 |
+
|
29 |
+
Although we make use of open source transformers to evaluate hallucination with Vectara, it is important to have experts and human evaluation to further maintain a trustworthy LLM system.
|
30 |
+
|
31 |
+
## Resources and Citation
|
32 |
+
* https://huggingface.co/docs/transformers/tasks/summarization
|
33 |
+
* https://huggingface.co/vectara/hallucination_evaluation_model
|
34 |
+
* https://github.com/vectara/hallucination-leaderboard
|
35 |
+
* https://www.nocode.ai/llms-undesirable-outputs/
|
36 |
+
* https://learn.deeplearning.ai/
|
37 |
+
* https://blog.langchain.dev/espilla-x-langchain-retrieval-augmented-generation-rag-in-llm-powered-question-answering-pipelines/
|
38 |
+
|
39 |
+
## Team Members
|
40 |
+
Vy Nguyen - Email: [email protected]
|
41 |
+
Andy Yang - Email: [email protected]
|
42 |
+
Gauri Bhandarwar - Email: [email protected]
|
43 |
+
Weining Mai - Email: [email protected]
|
Tagging/categories_tagging.md
ADDED
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
List of Category available: [Environmental, Education, Health Care, Criminal Justice, Taxation, Transportation, Housing, Civil Rights, Labor and Employment, Budget and Appropriations, Public Safety, Technology and Innovation, Immigration, Economic Development, Social Services]
|
2 |
+
|
3 |
+
Category: Environmental
|
4 |
+
|
5 |
+
Tags in Environmental
|
6 |
+
|
7 |
+
Climate Change Mitigation
|
8 |
+
Renewable Energy Initiatives
|
9 |
+
Biodiversity Conservation
|
10 |
+
Water Pollution Control
|
11 |
+
Sustainable Agriculture Practices
|
12 |
+
Air Quality Improvement
|
13 |
+
Waste Reduction Programs
|
14 |
+
Coastal Erosion Management
|
15 |
+
Environmental Impact Assessments
|
16 |
+
Wildlife Habitat Protection
|
17 |
+
|
18 |
+
Category: Education
|
19 |
+
|
20 |
+
Tags in Education
|
21 |
+
|
22 |
+
Curriculum Development
|
23 |
+
Digital Learning Resources
|
24 |
+
Teacher Professional Development
|
25 |
+
Early Childhood Education
|
26 |
+
Special Education Services
|
27 |
+
Literacy Programs
|
28 |
+
Vocational Training
|
29 |
+
Education Technology Integration
|
30 |
+
School Infrastructure Upgrades
|
31 |
+
Student Mental Health Support
|
32 |
+
|
33 |
+
Category: Health Care
|
34 |
+
|
35 |
+
Tags in Health Care
|
36 |
+
|
37 |
+
Universal Health Coverage
|
38 |
+
Healthcare Access for All
|
39 |
+
Mental Health Services Expansion
|
40 |
+
Disease Prevention Programs
|
41 |
+
Elderly Care Services
|
42 |
+
Healthcare Quality Standards
|
43 |
+
Health Information Technology
|
44 |
+
Maternal and Child Health
|
45 |
+
Public Health Emergency Preparedness
|
46 |
+
Healthcare Workforce Training
|
47 |
+
|
48 |
+
Categpry: Criminal Justice
|
49 |
+
|
50 |
+
Tags in Criminal Justice
|
51 |
+
|
52 |
+
Police Reforms
|
53 |
+
Prisoner Rehabilitation
|
54 |
+
Community Policing Initiatives
|
55 |
+
Restorative Justice Programs
|
56 |
+
Criminal Sentencing Reform
|
57 |
+
Victim Support Services
|
58 |
+
Legal Aid for the Underprivileged
|
59 |
+
Juvenile Justice System Overhaul
|
60 |
+
Hate Crime Prevention Measures
|
61 |
+
Court System Modernization
|
62 |
+
|
63 |
+
Category: Taxation
|
64 |
+
|
65 |
+
Tags in Taxation
|
66 |
+
|
67 |
+
Progressive Tax Reform
|
68 |
+
Corporate Taxation Policies
|
69 |
+
Income Tax Deductions
|
70 |
+
Property Tax Relief
|
71 |
+
Sales Tax Revision
|
72 |
+
Tax Compliance Regulations
|
73 |
+
Tax Transparency Measures
|
74 |
+
Wealth Redistribution Initiatives
|
75 |
+
Small Business Tax Breaks
|
76 |
+
Tax Fraud Prevention Measures
|
77 |
+
|
78 |
+
Category: Transportation
|
79 |
+
|
80 |
+
Tags in Transportation
|
81 |
+
|
82 |
+
Public Transit Expansion
|
83 |
+
Road Infrastructure Maintenance
|
84 |
+
Bike and Pedestrian Path Development
|
85 |
+
Traffic Congestion Reduction
|
86 |
+
Electric Vehicle Adoption Incentives
|
87 |
+
Freight Transportation Efficiency
|
88 |
+
Aviation Safety Regulations
|
89 |
+
Railroad Infrastructure Modernization
|
90 |
+
Intermodal Transportation Integration
|
91 |
+
Autonomous Vehicle Regulations
|
92 |
+
|
93 |
+
Category: Housing
|
94 |
+
|
95 |
+
Tags in Housing
|
96 |
+
|
97 |
+
Affordable Housing Development
|
98 |
+
Homelessness Prevention Programs
|
99 |
+
Rent Control Measures
|
100 |
+
Fair Housing Enforcement
|
101 |
+
Housing Discrimination Prevention
|
102 |
+
Housing Voucher Program Expansion
|
103 |
+
Sustainable Housing Initiatives
|
104 |
+
Urban Redevelopment Plans
|
105 |
+
Eviction Moratoriums
|
106 |
+
Homeownership Support Programs
|
107 |
+
|
108 |
+
Category: Civil Rights
|
109 |
+
|
110 |
+
Tags in Civil Rights
|
111 |
+
|
112 |
+
Anti-Discrimination Laws
|
113 |
+
Gender Equality Protections
|
114 |
+
LGBTQ+ Rights Advocacy
|
115 |
+
Disability Rights Enforcement
|
116 |
+
Indigenous Peoples' Rights
|
117 |
+
Religious Freedom Protection
|
118 |
+
Language Access Policies
|
119 |
+
Voting Rights Expansion
|
120 |
+
Equal Pay Legislation
|
121 |
+
Minority Rights Safeguards
|
122 |
+
|
123 |
+
Category: Labor and Employment
|
124 |
+
|
125 |
+
Tags in Labor and Employment
|
126 |
+
|
127 |
+
Minimum Wage Increase
|
128 |
+
Occupational Safety Regulations
|
129 |
+
Labor Union Protections
|
130 |
+
Workplace Harassment Prevention
|
131 |
+
Job Training and Apprenticeships
|
132 |
+
Workforce Diversity Initiatives
|
133 |
+
Employee Benefits Expansion
|
134 |
+
Fair Working Hours Regulations
|
135 |
+
Unemployment Benefits Enhancement
|
136 |
+
Remote Work Policies
|
137 |
+
|
138 |
+
Category: Budget and Appropriations
|
139 |
+
|
140 |
+
Tags in Budget and Appropriations
|
141 |
+
|
142 |
+
Government Spending Oversight
|
143 |
+
Emergency Fund Allocation
|
144 |
+
Public Debt Management
|
145 |
+
Fiscal Responsibility Audits
|
146 |
+
Public Infrastructure Investment
|
147 |
+
Social Welfare Program Funding
|
148 |
+
Pension Plan Reform
|
149 |
+
Local Government Grant Programs
|
150 |
+
Financial Aid for Disadvantaged Communities
|
151 |
+
Tax Revenue Allocation
|
152 |
+
|
153 |
+
Category: Public Safety
|
154 |
+
|
155 |
+
Tags in Public Safety
|
156 |
+
|
157 |
+
Emergency Response Planning
|
158 |
+
Disaster Preparedness Training
|
159 |
+
Cybersecurity Protocols
|
160 |
+
Domestic Violence Prevention
|
161 |
+
Fire Safety Regulations
|
162 |
+
Gun Control Measures
|
163 |
+
Community Health and Safety Programs
|
164 |
+
Public Health Crisis Management
|
165 |
+
Hate Crime Reporting Systems
|
166 |
+
Crime Prevention Initiatives
|
167 |
+
|
168 |
+
Category: Technology and Innovation
|
169 |
+
|
170 |
+
Tags in Technology and Innovation
|
171 |
+
|
172 |
+
Digital Privacy Laws
|
173 |
+
Data Security Measures
|
174 |
+
Innovation Investment Policies
|
175 |
+
Broadband Infrastructure Expansion
|
176 |
+
E-Government Service Enhancements
|
177 |
+
Technology Education in Schools
|
178 |
+
Artificial Intelligence Regulations
|
179 |
+
Privacy Protection for Biometric Data
|
180 |
+
Blockchain Integration Strategies
|
181 |
+
Open Data Initiatives
|
182 |
+
|
183 |
+
Category: Immigration
|
184 |
+
|
185 |
+
Tags in Immigration
|
186 |
+
|
187 |
+
Immigration Policy Reform
|
188 |
+
Refugee Resettlement Programs
|
189 |
+
Asylum Seeker Protections
|
190 |
+
Migrant Worker Rights
|
191 |
+
Language Access Services
|
192 |
+
Family Reunification Initiatives
|
193 |
+
Pathways to Citizenship
|
194 |
+
Humanitarian Aid for Migrants
|
195 |
+
Border Security Measures
|
196 |
+
Anti-Trafficking Efforts
|
197 |
+
|
198 |
+
Category: Economic Development
|
199 |
+
|
200 |
+
Tags in Economic Development
|
201 |
+
|
202 |
+
Small Business Support Programs
|
203 |
+
Export Promotion Policies
|
204 |
+
Rural Development Initiatives
|
205 |
+
Entrepreneurship Training
|
206 |
+
Trade Agreement Negotiations
|
207 |
+
Tourism Industry Growth
|
208 |
+
Regional Economic Integration
|
209 |
+
Financial Inclusion Programs
|
210 |
+
Economic Diversification Strategies
|
211 |
+
Infrastructure Investment Plans
|
212 |
+
|
213 |
+
Category: Social Services
|
214 |
+
|
215 |
+
Tags in Social Services
|
216 |
+
|
217 |
+
Child Welfare Services
|
218 |
+
Domestic Violence Support
|
219 |
+
Elderly Care Programs
|
220 |
+
Foster Care System Reforms
|
221 |
+
Disability Assistance Programs
|
222 |
+
Community Support Services
|
223 |
+
Youth Mentorship Programs
|
224 |
+
Substance Abuse Rehabilitation
|
225 |
+
Home Care for the Disabled
|
226 |
+
Affordable Childcare Services
|
Tagging/prompts.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Prompt 1
|
2 |
+
prompt_template = """Use the context below to assign a category that is relevant.
|
3 |
+
After assigning a category, I want you to assign three tags in the chosen category that are relevant to the context
|
4 |
+
|
5 |
+
Context: {context}
|
6 |
+
info: {tagging}
|
7 |
+
"""
|
Tagging/readme.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
List of files that are classifying taggings.
|
Tagging/tagging_testing.ipynb
ADDED
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 16,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Collecting tiktoken\n",
|
13 |
+
" Obtaining dependency information for tiktoken from https://files.pythonhosted.org/packages/b8/eb/234646d9eefda8a500d0fd88b05bf625a90ed18054124349db26e558276e/tiktoken-0.5.1-cp311-cp311-win_amd64.whl.metadata\n",
|
14 |
+
" Downloading tiktoken-0.5.1-cp311-cp311-win_amd64.whl.metadata (6.8 kB)\n",
|
15 |
+
"Collecting regex>=2022.1.18 (from tiktoken)\n",
|
16 |
+
" Obtaining dependency information for regex>=2022.1.18 from https://files.pythonhosted.org/packages/b8/ad/3398312096118c4e62a5827664e52a04d5068e84d04142dd4a0da8a567ae/regex-2023.10.3-cp311-cp311-win_amd64.whl.metadata\n",
|
17 |
+
" Downloading regex-2023.10.3-cp311-cp311-win_amd64.whl.metadata (41 kB)\n",
|
18 |
+
" ---------------------------------------- 0.0/42.0 kB ? eta -:--:--\n",
|
19 |
+
" ------------------ ------------------- 20.5/42.0 kB 320.0 kB/s eta 0:00:01\n",
|
20 |
+
" -------------------------------------- 42.0/42.0 kB 503.7 kB/s eta 0:00:00\n",
|
21 |
+
"Requirement already satisfied: requests>=2.26.0 in c:\\users\\16178\\anaconda3\\envs\\llama\\lib\\site-packages (from tiktoken) (2.31.0)\n",
|
22 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\16178\\anaconda3\\envs\\llama\\lib\\site-packages (from requests>=2.26.0->tiktoken) (2.0.4)\n",
|
23 |
+
"Requirement already satisfied: idna<4,>=2.5 in c:\\users\\16178\\anaconda3\\envs\\llama\\lib\\site-packages (from requests>=2.26.0->tiktoken) (3.4)\n",
|
24 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\16178\\anaconda3\\envs\\llama\\lib\\site-packages (from requests>=2.26.0->tiktoken) (1.26.16)\n",
|
25 |
+
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\16178\\anaconda3\\envs\\llama\\lib\\site-packages (from requests>=2.26.0->tiktoken) (2023.7.22)\n",
|
26 |
+
"Downloading tiktoken-0.5.1-cp311-cp311-win_amd64.whl (759 kB)\n",
|
27 |
+
" ---------------------------------------- 0.0/759.8 kB ? eta -:--:--\n",
|
28 |
+
" --- ------------------------------------ 61.4/759.8 kB 1.7 MB/s eta 0:00:01\n",
|
29 |
+
" ----------------- ---------------------- 327.7/759.8 kB 4.1 MB/s eta 0:00:01\n",
|
30 |
+
" ------------------------------------ --- 686.1/759.8 kB 5.4 MB/s eta 0:00:01\n",
|
31 |
+
" ---------------------------------------- 759.8/759.8 kB 5.4 MB/s eta 0:00:00\n",
|
32 |
+
"Downloading regex-2023.10.3-cp311-cp311-win_amd64.whl (269 kB)\n",
|
33 |
+
" ---------------------------------------- 0.0/269.6 kB ? eta -:--:--\n",
|
34 |
+
" ------------------------------------ --- 245.8/269.6 kB 7.4 MB/s eta 0:00:01\n",
|
35 |
+
" ---------------------------------------- 269.6/269.6 kB 4.1 MB/s eta 0:00:00\n",
|
36 |
+
"Installing collected packages: regex, tiktoken\n",
|
37 |
+
"Successfully installed regex-2023.10.3 tiktoken-0.5.1\n",
|
38 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
39 |
+
]
|
40 |
+
}
|
41 |
+
],
|
42 |
+
"source": [
|
43 |
+
"pip install tiktoken chromadb"
|
44 |
+
]
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"cell_type": "code",
|
48 |
+
"execution_count": 1,
|
49 |
+
"metadata": {},
|
50 |
+
"outputs": [],
|
51 |
+
"source": [
|
52 |
+
"# you need openai key\n",
|
53 |
+
"import os\n",
|
54 |
+
"os.environ['OPENAI_API_KEY'] = ''"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": 25,
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"from langchain.prompts import PromptTemplate\n",
|
64 |
+
"from langchain.chains import LLMChain\n",
|
65 |
+
"from langchain.llms import OpenAI\n",
|
66 |
+
"from langchain.chat_models import ChatOpenAI\n",
|
67 |
+
"from langchain.callbacks import get_openai_callback\n",
|
68 |
+
"from langchain.schema import StrOutputParser"
|
69 |
+
]
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"cell_type": "code",
|
73 |
+
"execution_count": 13,
|
74 |
+
"metadata": {},
|
75 |
+
"outputs": [],
|
76 |
+
"source": [
|
77 |
+
"category = \"\"\"\n",
|
78 |
+
"[Environmental, Education, Health Care, Criminal Justice, Taxation, Transportation, \n",
|
79 |
+
"Housing, Civil Rights, Labor and Employment, Budget and Appropriations, Public Safety, Technology and Innovation, \n",
|
80 |
+
"Immigration, Economic Development, Social Services]\n",
|
81 |
+
"\"\"\""
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 23,
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [],
|
89 |
+
"source": [
|
90 |
+
"tagging = \"\"\"\n",
|
91 |
+
"[Climate Change Mitigation,\n",
|
92 |
+
"Renewable Energy Initiatives,\n",
|
93 |
+
"Biodiversity Conservation,\n",
|
94 |
+
"Water Pollution Control,\n",
|
95 |
+
"Sustainable Agriculture Practices,\n",
|
96 |
+
"Air Quality Improvement,\n",
|
97 |
+
"Waste Reduction Programs,\n",
|
98 |
+
"Coastal Erosion Management,\n",
|
99 |
+
"Environmental Impact Assessments,\n",
|
100 |
+
"Wildlife Habitat Protection,\n",
|
101 |
+
"Curriculum Development,\n",
|
102 |
+
"Digital Learning Resources,\n",
|
103 |
+
"Teacher Professional Development,\n",
|
104 |
+
"Early Childhood Education,\n",
|
105 |
+
"Special Education Services,\n",
|
106 |
+
"Literacy Programs,\n",
|
107 |
+
"Vocational Training,\n",
|
108 |
+
"Education Technology Integration,\n",
|
109 |
+
"School Infrastructure Upgrades,\n",
|
110 |
+
"Student Mental Health Support,\n",
|
111 |
+
"Universal Health Coverage,\n",
|
112 |
+
"Healthcare Access for All,\n",
|
113 |
+
"Mental Health Services Expansion,\n",
|
114 |
+
"Disease Prevention Programs,\n",
|
115 |
+
"Elderly Care Services,\n",
|
116 |
+
"Healthcare Quality Standards,\n",
|
117 |
+
"Health Information Technology,\n",
|
118 |
+
"Maternal and Child Health,\n",
|
119 |
+
"Public Health Emergency Preparedness,\n",
|
120 |
+
"Healthcare Workforce Training,\n",
|
121 |
+
"Police Reforms\n",
|
122 |
+
"Prisoner Rehabilitation\n",
|
123 |
+
"Community Policing Initiatives\n",
|
124 |
+
"Restorative Justice Programs\n",
|
125 |
+
"Criminal Sentencing Reform\n",
|
126 |
+
"Victim Support Services\n",
|
127 |
+
"Legal Aid for the Underprivileged\n",
|
128 |
+
"Juvenile Justice System Overhaul\n",
|
129 |
+
"Hate Crime Prevention Measures\n",
|
130 |
+
"Court System Modernization,\n",
|
131 |
+
"Progressive Tax Reform\n",
|
132 |
+
"Corporate Taxation Policies\n",
|
133 |
+
"Income Tax Deductions\n",
|
134 |
+
"Property Tax Relief\n",
|
135 |
+
"Sales Tax Revision\n",
|
136 |
+
"Tax Compliance Regulations\n",
|
137 |
+
"Tax Transparency Measures\n",
|
138 |
+
"Wealth Redistribution Initiatives\n",
|
139 |
+
"Small Business Tax Breaks\n",
|
140 |
+
"Tax Fraud Prevention Measures,\n",
|
141 |
+
"Public Transit Expansion\n",
|
142 |
+
"Road Infrastructure Maintenance\n",
|
143 |
+
"Bike and Pedestrian Path Development\n",
|
144 |
+
"Traffic Congestion Reduction\n",
|
145 |
+
"Electric Vehicle Adoption Incentives\n",
|
146 |
+
"Freight Transportation Efficiency\n",
|
147 |
+
"Aviation Safety Regulations\n",
|
148 |
+
"Railroad Infrastructure Modernization\n",
|
149 |
+
"Intermodal Transportation Integration\n",
|
150 |
+
"Autonomous Vehicle Regulations,\n",
|
151 |
+
"Affordable Housing Development\n",
|
152 |
+
"Homelessness Prevention Programs\n",
|
153 |
+
"Rent Control Measures\n",
|
154 |
+
"Fair Housing Enforcement\n",
|
155 |
+
"Housing Discrimination Prevention\n",
|
156 |
+
"Housing Voucher Program Expansion\n",
|
157 |
+
"Sustainable Housing Initiatives\n",
|
158 |
+
"Urban Redevelopment Plans\n",
|
159 |
+
"Eviction Moratoriums\n",
|
160 |
+
"Homeownership Support Programs,\n",
|
161 |
+
"Anti-Discrimination Laws\n",
|
162 |
+
"Gender Equality Protections\n",
|
163 |
+
"LGBTQ+ Rights Advocacy\n",
|
164 |
+
"Disability Rights Enforcement\n",
|
165 |
+
"Indigenous Peoples' Rights\n",
|
166 |
+
"Religious Freedom Protection\n",
|
167 |
+
"Language Access Policies\n",
|
168 |
+
"Voting Rights Expansion\n",
|
169 |
+
"Equal Pay Legislation\n",
|
170 |
+
"Minority Rights Safeguards,\n",
|
171 |
+
"Minimum Wage Increase\n",
|
172 |
+
"Occupational Safety Regulations\n",
|
173 |
+
"Labor Union Protections\n",
|
174 |
+
"Workplace Harassment Prevention\n",
|
175 |
+
"Job Training and Apprenticeships\n",
|
176 |
+
"Workforce Diversity Initiatives\n",
|
177 |
+
"Employee Benefits Expansion\n",
|
178 |
+
"Fair Working Hours Regulations\n",
|
179 |
+
"Unemployment Benefits Enhancement\n",
|
180 |
+
"Remote Work Policies,\n",
|
181 |
+
"Government Spending Oversight\n",
|
182 |
+
"Emergency Fund Allocation\n",
|
183 |
+
"Public Debt Management\n",
|
184 |
+
"Fiscal Responsibility Audits\n",
|
185 |
+
"Public Infrastructure Investment\n",
|
186 |
+
"Social Welfare Program Funding\n",
|
187 |
+
"Pension Plan Reform\n",
|
188 |
+
"Local Government Grant Programs\n",
|
189 |
+
"Financial Aid for Disadvantaged Communities\n",
|
190 |
+
"Tax Revenue Allocation,\n",
|
191 |
+
"Emergency Response Planning\n",
|
192 |
+
"Disaster Preparedness Training\n",
|
193 |
+
"Cybersecurity Protocols\n",
|
194 |
+
"Domestic Violence Prevention\n",
|
195 |
+
"Fire Safety Regulations\n",
|
196 |
+
"Gun Control Measures\n",
|
197 |
+
"Community Health and Safety Programs\n",
|
198 |
+
"Public Health Crisis Management\n",
|
199 |
+
"Hate Crime Reporting Systems\n",
|
200 |
+
"Crime Prevention Initiatives,\n",
|
201 |
+
"Digital Privacy Laws\n",
|
202 |
+
"Data Security Measures\n",
|
203 |
+
"Innovation Investment Policies\n",
|
204 |
+
"Broadband Infrastructure Expansion\n",
|
205 |
+
"E-Government Service Enhancements\n",
|
206 |
+
"Technology Education in Schools\n",
|
207 |
+
"Artificial Intelligence Regulations\n",
|
208 |
+
"Privacy Protection for Biometric Data\n",
|
209 |
+
"Blockchain Integration Strategies\n",
|
210 |
+
"Open Data Initiatives,\n",
|
211 |
+
"Immigration Policy Reform\n",
|
212 |
+
"Refugee Resettlement Programs\n",
|
213 |
+
"Asylum Seeker Protections\n",
|
214 |
+
"Migrant Worker Rights\n",
|
215 |
+
"Language Access Services\n",
|
216 |
+
"Family Reunification Initiatives\n",
|
217 |
+
"Pathways to Citizenship\n",
|
218 |
+
"Humanitarian Aid for Migrants\n",
|
219 |
+
"Border Security Measures\n",
|
220 |
+
"Anti-Trafficking Efforts,\n",
|
221 |
+
"Small Business Support Programs\n",
|
222 |
+
"Export Promotion Policies\n",
|
223 |
+
"Rural Development Initiatives\n",
|
224 |
+
"Entrepreneurship Training\n",
|
225 |
+
"Trade Agreement Negotiations\n",
|
226 |
+
"Tourism Industry Growth\n",
|
227 |
+
"Regional Economic Integration\n",
|
228 |
+
"Financial Inclusion Programs\n",
|
229 |
+
"Economic Diversification Strategies\n",
|
230 |
+
"Infrastructure Investment Plans,\n",
|
231 |
+
"Child Welfare Services\n",
|
232 |
+
"Domestic Violence Support\n",
|
233 |
+
"Elderly Care Programs\n",
|
234 |
+
"Foster Care System Reforms\n",
|
235 |
+
"Disability Assistance Programs\n",
|
236 |
+
"Community Support Services\n",
|
237 |
+
"Youth Mentorship Programs\n",
|
238 |
+
"Substance Abuse Rehabilitation\n",
|
239 |
+
"Home Care for the Disabled\n",
|
240 |
+
"Affordable Childcare Services\n",
|
241 |
+
"]\n",
|
242 |
+
"\"\"\""
|
243 |
+
]
|
244 |
+
},
|
245 |
+
{
|
246 |
+
"cell_type": "code",
|
247 |
+
"execution_count": 21,
|
248 |
+
"metadata": {},
|
249 |
+
"outputs": [],
|
250 |
+
"source": [
|
251 |
+
"# LLM\n",
|
252 |
+
"prompt_template = \"\"\"Use the context below to assign a category that is relevant to the category, which is delimited by ####\n",
|
253 |
+
"Also, I want you to use the tagging, which is delimited by ****, and give top 3 tags that fit the context.\n",
|
254 |
+
"\n",
|
255 |
+
"Context: {context}\n",
|
256 |
+
"Category: {category}\n",
|
257 |
+
"tagging: {tags}\n",
|
258 |
+
"Do not make up false information\n",
|
259 |
+
"\"\"\""
|
260 |
+
]
|
261 |
+
},
|
262 |
+
{
|
263 |
+
"cell_type": "code",
|
264 |
+
"execution_count": 26,
|
265 |
+
"metadata": {},
|
266 |
+
"outputs": [
|
267 |
+
{
|
268 |
+
"name": "stdout",
|
269 |
+
"output_type": "stream",
|
270 |
+
"text": [
|
271 |
+
"Total Tokens: 1069\n",
|
272 |
+
"Prompt Tokens: 1040\n",
|
273 |
+
"Completion Tokens: 29\n",
|
274 |
+
"Total Cost (USD): $0.0016180000000000003\n",
|
275 |
+
"\n",
|
276 |
+
"SECTION 1. Chapter 20 Section 23 of the General Laws, as appearing in the 2020 Official Edition, is hereby amended by inserting the following after section (f): -\n",
|
277 |
+
"\t(g) Notwithstanding any general or special law to the contrary, the department of agricultural resources, \n",
|
278 |
+
" with the approval of the co-holder, if any, in its sole discretion, may allow for storm water mitigation or nitrogen mitigation purposes, \n",
|
279 |
+
" in nitrogen sensitive embayment watersheds, uncultivated, planted or other storm water mitigation infrastructure within 200 feet of any resource area in any parcel \n",
|
280 |
+
" that has been accepted into the Massachusetts Agricultural Preservation Restriction program.\n",
|
281 |
+
"Category: Environmental\n",
|
282 |
+
"\n",
|
283 |
+
"Top 3 tags: \n",
|
284 |
+
"1. Water Pollution Control\n",
|
285 |
+
"2. Sustainable Agriculture Practices\n",
|
286 |
+
"3. Coastal Erosion Management\n"
|
287 |
+
]
|
288 |
+
}
|
289 |
+
],
|
290 |
+
"source": [
|
291 |
+
"info = \"\"\"\n",
|
292 |
+
"SECTION 1. Chapter 20 Section 23 of the General Laws, as appearing in the 2020 Official Edition, is hereby amended by inserting the following after section (f): -\n",
|
293 |
+
"\t(g) Notwithstanding any general or special law to the contrary, the department of agricultural resources, \n",
|
294 |
+
" with the approval of the co-holder, if any, in its sole discretion, may allow for storm water mitigation or nitrogen mitigation purposes, \n",
|
295 |
+
" in nitrogen sensitive embayment watersheds, uncultivated, planted or other storm water mitigation infrastructure within 200 feet of any resource area in any parcel \n",
|
296 |
+
" that has been accepted into the Massachusetts Agricultural Preservation Restriction program.\"\"\"\n",
|
297 |
+
"\n",
|
298 |
+
"\n",
|
299 |
+
"PROMPT = PromptTemplate(template=prompt_template, input_variables=[\"context\", \"category\", 'tags'])\n",
|
300 |
+
"\n",
|
301 |
+
"with get_openai_callback() as cb:\n",
|
302 |
+
" llm = LLMChain(\n",
|
303 |
+
" llm = ChatOpenAI(openai_api_key='',\n",
|
304 |
+
" temperature=0.01, model=\"gpt-3.5-turbo\"), prompt=PROMPT)\n",
|
305 |
+
" \n",
|
306 |
+
" response = llm.predict(context=info, category=category, tags=tagging)\n",
|
307 |
+
" print(f\"Total Tokens: {cb.total_tokens}\")\n",
|
308 |
+
" print(f\"Prompt Tokens: {cb.prompt_tokens}\")\n",
|
309 |
+
" print(f\"Completion Tokens: {cb.completion_tokens}\")\n",
|
310 |
+
" print(f\"Total Cost (USD): ${cb.total_cost}\")\n",
|
311 |
+
" \n",
|
312 |
+
"print(info)\n",
|
313 |
+
"print(response)"
|
314 |
+
]
|
315 |
+
},
|
316 |
+
{
|
317 |
+
"cell_type": "code",
|
318 |
+
"execution_count": null,
|
319 |
+
"metadata": {},
|
320 |
+
"outputs": [],
|
321 |
+
"source": []
|
322 |
+
}
|
323 |
+
],
|
324 |
+
"metadata": {
|
325 |
+
"kernelspec": {
|
326 |
+
"display_name": "llama",
|
327 |
+
"language": "python",
|
328 |
+
"name": "python3"
|
329 |
+
},
|
330 |
+
"language_info": {
|
331 |
+
"codemirror_mode": {
|
332 |
+
"name": "ipython",
|
333 |
+
"version": 3
|
334 |
+
},
|
335 |
+
"file_extension": ".py",
|
336 |
+
"mimetype": "text/x-python",
|
337 |
+
"name": "python",
|
338 |
+
"nbconvert_exporter": "python",
|
339 |
+
"pygments_lexer": "ipython3",
|
340 |
+
"version": "3.11.5"
|
341 |
+
}
|
342 |
+
},
|
343 |
+
"nbformat": 4,
|
344 |
+
"nbformat_minor": 2
|
345 |
+
}
|
demoapp/12billswithmgl.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
demoapp/MGL_extract.ipynb
ADDED
@@ -0,0 +1,827 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"data": {
|
10 |
+
"text/html": [
|
11 |
+
"<div>\n",
|
12 |
+
"<style scoped>\n",
|
13 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
14 |
+
" vertical-align: middle;\n",
|
15 |
+
" }\n",
|
16 |
+
"\n",
|
17 |
+
" .dataframe tbody tr th {\n",
|
18 |
+
" vertical-align: top;\n",
|
19 |
+
" }\n",
|
20 |
+
"\n",
|
21 |
+
" .dataframe thead th {\n",
|
22 |
+
" text-align: right;\n",
|
23 |
+
" }\n",
|
24 |
+
"</style>\n",
|
25 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
26 |
+
" <thead>\n",
|
27 |
+
" <tr style=\"text-align: right;\">\n",
|
28 |
+
" <th></th>\n",
|
29 |
+
" <th>Unnamed: 0</th>\n",
|
30 |
+
" <th>Title</th>\n",
|
31 |
+
" <th>BillNumber</th>\n",
|
32 |
+
" <th>DocketNumber</th>\n",
|
33 |
+
" <th>GeneralCourtNumber</th>\n",
|
34 |
+
" <th>PrimarySponsor</th>\n",
|
35 |
+
" <th>Cosponsors</th>\n",
|
36 |
+
" <th>JointSponsor</th>\n",
|
37 |
+
" <th>BillHistory</th>\n",
|
38 |
+
" <th>LegislationTypeName</th>\n",
|
39 |
+
" <th>Pinslip</th>\n",
|
40 |
+
" <th>DocumentText</th>\n",
|
41 |
+
" <th>EmergencyPreamble</th>\n",
|
42 |
+
" <th>RollCalls</th>\n",
|
43 |
+
" <th>Attachments</th>\n",
|
44 |
+
" <th>CommitteeRecommendations</th>\n",
|
45 |
+
" <th>Amendments</th>\n",
|
46 |
+
" <th>List References</th>\n",
|
47 |
+
" </tr>\n",
|
48 |
+
" </thead>\n",
|
49 |
+
" <tbody>\n",
|
50 |
+
" <tr>\n",
|
51 |
+
" <th>0</th>\n",
|
52 |
+
" <td>2299</td>\n",
|
53 |
+
" <td>An Act relative to collective bargaining right...</td>\n",
|
54 |
+
" <td>H3069</td>\n",
|
55 |
+
" <td>HD2435</td>\n",
|
56 |
+
" <td>193.0</td>\n",
|
57 |
+
" <td>{'Id': 'PJK1', 'Name': 'Patrick Joseph Kearney...</td>\n",
|
58 |
+
" <td>[{'Id': 'PJK1', 'Name': 'Patrick Joseph Kearne...</td>\n",
|
59 |
+
" <td>NaN</td>\n",
|
60 |
+
" <td>http://malegislature.gov/api/GeneralCourts/193...</td>\n",
|
61 |
+
" <td>Bill</td>\n",
|
62 |
+
" <td>By Representative Kearney of Scituate, a petit...</td>\n",
|
63 |
+
" <td>\\tSECTION 1. Section 1 of Chapter 150E of the ...</td>\n",
|
64 |
+
" <td>NaN</td>\n",
|
65 |
+
" <td>[]</td>\n",
|
66 |
+
" <td>[]</td>\n",
|
67 |
+
" <td>[]</td>\n",
|
68 |
+
" <td>[]</td>\n",
|
69 |
+
" <td>[['1', '150E'], ['23', '268A']]</td>\n",
|
70 |
+
" </tr>\n",
|
71 |
+
" <tr>\n",
|
72 |
+
" <th>1</th>\n",
|
73 |
+
" <td>2358</td>\n",
|
74 |
+
" <td>An Act relative to the open meeting law</td>\n",
|
75 |
+
" <td>H3121</td>\n",
|
76 |
+
" <td>HD2204</td>\n",
|
77 |
+
" <td>193.0</td>\n",
|
78 |
+
" <td>{'Id': 'E_U1', 'Name': 'Erika Uyterhoeven', 'T...</td>\n",
|
79 |
+
" <td>[{'Id': 'E_U1', 'Name': 'Erika Uyterhoeven', '...</td>\n",
|
80 |
+
" <td>NaN</td>\n",
|
81 |
+
" <td>http://malegislature.gov/api/GeneralCourts/193...</td>\n",
|
82 |
+
" <td>Bill</td>\n",
|
83 |
+
" <td>By Representative Uyterhoeven of Somerville, a...</td>\n",
|
84 |
+
" <td>\\tSECTION 18 of chapter 30A of the General Law...</td>\n",
|
85 |
+
" <td>NaN</td>\n",
|
86 |
+
" <td>[]</td>\n",
|
87 |
+
" <td>[]</td>\n",
|
88 |
+
" <td>[]</td>\n",
|
89 |
+
" <td>[]</td>\n",
|
90 |
+
" <td>[['18', '30A']]</td>\n",
|
91 |
+
" </tr>\n",
|
92 |
+
" </tbody>\n",
|
93 |
+
"</table>\n",
|
94 |
+
"</div>"
|
95 |
+
],
|
96 |
+
"text/plain": [
|
97 |
+
" Unnamed: 0 Title BillNumber \\\n",
|
98 |
+
"0 2299 An Act relative to collective bargaining right... H3069 \n",
|
99 |
+
"1 2358 An Act relative to the open meeting law H3121 \n",
|
100 |
+
"\n",
|
101 |
+
" DocketNumber GeneralCourtNumber \\\n",
|
102 |
+
"0 HD2435 193.0 \n",
|
103 |
+
"1 HD2204 193.0 \n",
|
104 |
+
"\n",
|
105 |
+
" PrimarySponsor \\\n",
|
106 |
+
"0 {'Id': 'PJK1', 'Name': 'Patrick Joseph Kearney... \n",
|
107 |
+
"1 {'Id': 'E_U1', 'Name': 'Erika Uyterhoeven', 'T... \n",
|
108 |
+
"\n",
|
109 |
+
" Cosponsors JointSponsor \\\n",
|
110 |
+
"0 [{'Id': 'PJK1', 'Name': 'Patrick Joseph Kearne... NaN \n",
|
111 |
+
"1 [{'Id': 'E_U1', 'Name': 'Erika Uyterhoeven', '... NaN \n",
|
112 |
+
"\n",
|
113 |
+
" BillHistory LegislationTypeName \\\n",
|
114 |
+
"0 http://malegislature.gov/api/GeneralCourts/193... Bill \n",
|
115 |
+
"1 http://malegislature.gov/api/GeneralCourts/193... Bill \n",
|
116 |
+
"\n",
|
117 |
+
" Pinslip \\\n",
|
118 |
+
"0 By Representative Kearney of Scituate, a petit... \n",
|
119 |
+
"1 By Representative Uyterhoeven of Somerville, a... \n",
|
120 |
+
"\n",
|
121 |
+
" DocumentText EmergencyPreamble \\\n",
|
122 |
+
"0 \\tSECTION 1. Section 1 of Chapter 150E of the ... NaN \n",
|
123 |
+
"1 \\tSECTION 18 of chapter 30A of the General Law... NaN \n",
|
124 |
+
"\n",
|
125 |
+
" RollCalls Attachments CommitteeRecommendations Amendments \\\n",
|
126 |
+
"0 [] [] [] [] \n",
|
127 |
+
"1 [] [] [] [] \n",
|
128 |
+
"\n",
|
129 |
+
" List References \n",
|
130 |
+
"0 [['1', '150E'], ['23', '268A']] \n",
|
131 |
+
"1 [['18', '30A']] "
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"execution_count": 2,
|
135 |
+
"metadata": {},
|
136 |
+
"output_type": "execute_result"
|
137 |
+
}
|
138 |
+
],
|
139 |
+
"source": [
|
140 |
+
"import requests\n",
|
141 |
+
"import pandas as pd\n",
|
142 |
+
"\n",
|
143 |
+
"df = pd.read_csv(\"list_regex_format_12bills.csv\")\n",
|
144 |
+
"df.head(2)"
|
145 |
+
]
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"cell_type": "markdown",
|
149 |
+
"metadata": {},
|
150 |
+
"source": [
|
151 |
+
"List References: section number and chapter format"
|
152 |
+
]
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"cell_type": "code",
|
156 |
+
"execution_count": 3,
|
157 |
+
"metadata": {},
|
158 |
+
"outputs": [
|
159 |
+
{
|
160 |
+
"data": {
|
161 |
+
"text/plain": [
|
162 |
+
"0 [['1', '150E'], ['23', '268A']]\n",
|
163 |
+
"1 [['18', '30A']]\n",
|
164 |
+
"2 NaN\n",
|
165 |
+
"3 [['2', '15D'], ['2', '18B'], ['11', '15D'], ['...\n",
|
166 |
+
"4 [['10', '70B']]\n",
|
167 |
+
"5 [['77', '54']]\n",
|
168 |
+
"6 [['1', '125'], ['73', '7C']]\n",
|
169 |
+
"7 [['1', '150E'], ['23', '268A']]\n",
|
170 |
+
"8 [['7', '4'], ['7', '4'], ['10', '66']]\n",
|
171 |
+
"9 NaN\n",
|
172 |
+
"10 [['2', '15D'], ['2', '18B'], ['11', '15D'], ['...\n",
|
173 |
+
"11 [['77', '54']]\n",
|
174 |
+
"Name: List References, dtype: object"
|
175 |
+
]
|
176 |
+
},
|
177 |
+
"execution_count": 3,
|
178 |
+
"metadata": {},
|
179 |
+
"output_type": "execute_result"
|
180 |
+
}
|
181 |
+
],
|
182 |
+
"source": [
|
183 |
+
"df['List References'] "
|
184 |
+
]
|
185 |
+
},
|
186 |
+
{
|
187 |
+
"cell_type": "markdown",
|
188 |
+
"metadata": {},
|
189 |
+
"source": [
|
190 |
+
"List References: section number and chapter format"
|
191 |
+
]
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"cell_type": "code",
|
195 |
+
"execution_count": 4,
|
196 |
+
"metadata": {},
|
197 |
+
"outputs": [
|
198 |
+
{
|
199 |
+
"data": {
|
200 |
+
"text/html": [
|
201 |
+
"<div>\n",
|
202 |
+
"<style scoped>\n",
|
203 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
204 |
+
" vertical-align: middle;\n",
|
205 |
+
" }\n",
|
206 |
+
"\n",
|
207 |
+
" .dataframe tbody tr th {\n",
|
208 |
+
" vertical-align: top;\n",
|
209 |
+
" }\n",
|
210 |
+
"\n",
|
211 |
+
" .dataframe thead th {\n",
|
212 |
+
" text-align: right;\n",
|
213 |
+
" }\n",
|
214 |
+
"</style>\n",
|
215 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
216 |
+
" <thead>\n",
|
217 |
+
" <tr style=\"text-align: right;\">\n",
|
218 |
+
" <th></th>\n",
|
219 |
+
" <th>Title</th>\n",
|
220 |
+
" <th>BillNumber</th>\n",
|
221 |
+
" <th>DocketNumber</th>\n",
|
222 |
+
" <th>DocumentText</th>\n",
|
223 |
+
" <th>List References</th>\n",
|
224 |
+
" </tr>\n",
|
225 |
+
" </thead>\n",
|
226 |
+
" <tbody>\n",
|
227 |
+
" <tr>\n",
|
228 |
+
" <th>0</th>\n",
|
229 |
+
" <td>An Act relative to collective bargaining right...</td>\n",
|
230 |
+
" <td>H3069</td>\n",
|
231 |
+
" <td>HD2435</td>\n",
|
232 |
+
" <td>\\tSECTION 1. Section 1 of Chapter 150E of the ...</td>\n",
|
233 |
+
" <td>[['1', '150E'], ['23', '268A']]</td>\n",
|
234 |
+
" </tr>\n",
|
235 |
+
" <tr>\n",
|
236 |
+
" <th>1</th>\n",
|
237 |
+
" <td>An Act relative to the open meeting law</td>\n",
|
238 |
+
" <td>H3121</td>\n",
|
239 |
+
" <td>HD2204</td>\n",
|
240 |
+
" <td>\\tSECTION 18 of chapter 30A of the General Law...</td>\n",
|
241 |
+
" <td>[['18', '30A']]</td>\n",
|
242 |
+
" </tr>\n",
|
243 |
+
" <tr>\n",
|
244 |
+
" <th>2</th>\n",
|
245 |
+
" <td>An Act relative to vehicle recalls</td>\n",
|
246 |
+
" <td>H400</td>\n",
|
247 |
+
" <td>HD1240</td>\n",
|
248 |
+
" <td>\\tSECTION 1. Chapter 90 of the General Laws, a...</td>\n",
|
249 |
+
" <td>NaN</td>\n",
|
250 |
+
" </tr>\n",
|
251 |
+
" <tr>\n",
|
252 |
+
" <th>3</th>\n",
|
253 |
+
" <td>An Act providing affordable and accessible hig...</td>\n",
|
254 |
+
" <td>H489</td>\n",
|
255 |
+
" <td>HD2794</td>\n",
|
256 |
+
" <td>\\tSECTION 1. The seventh paragraph of section ...</td>\n",
|
257 |
+
" <td>[['2', '15D'], ['2', '18B'], ['11', '15D'], ['...</td>\n",
|
258 |
+
" </tr>\n",
|
259 |
+
" <tr>\n",
|
260 |
+
" <th>4</th>\n",
|
261 |
+
" <td>An Act to Improve access, opportunity, and cap...</td>\n",
|
262 |
+
" <td>H538</td>\n",
|
263 |
+
" <td>HD485</td>\n",
|
264 |
+
" <td>\\tSECTION 1. To create a new capital infrastru...</td>\n",
|
265 |
+
" <td>[['10', '70B']]</td>\n",
|
266 |
+
" </tr>\n",
|
267 |
+
" <tr>\n",
|
268 |
+
" <th>5</th>\n",
|
269 |
+
" <td>An Act providing a local option for ranked cho...</td>\n",
|
270 |
+
" <td>H711</td>\n",
|
271 |
+
" <td>HD1183</td>\n",
|
272 |
+
" <td>\\tSECTION 1. Section 44A of chapter 43 of the ...</td>\n",
|
273 |
+
" <td>[['77', '54']]</td>\n",
|
274 |
+
" </tr>\n",
|
275 |
+
" <tr>\n",
|
276 |
+
" <th>6</th>\n",
|
277 |
+
" <td>An Act establishing a jail and prison construc...</td>\n",
|
278 |
+
" <td>S1979</td>\n",
|
279 |
+
" <td>SD661</td>\n",
|
280 |
+
" <td>\\tSECTION 1. Chapter 7C of the General Laws is...</td>\n",
|
281 |
+
" <td>[['1', '125'], ['73', '7C']]</td>\n",
|
282 |
+
" </tr>\n",
|
283 |
+
" <tr>\n",
|
284 |
+
" <th>7</th>\n",
|
285 |
+
" <td>An Act relative to collective bargaining right...</td>\n",
|
286 |
+
" <td>S2014</td>\n",
|
287 |
+
" <td>SD1208</td>\n",
|
288 |
+
" <td>\\tSECTION 1. Section 1 of chapter 150E of the ...</td>\n",
|
289 |
+
" <td>[['1', '150E'], ['23', '268A']]</td>\n",
|
290 |
+
" </tr>\n",
|
291 |
+
" <tr>\n",
|
292 |
+
" <th>8</th>\n",
|
293 |
+
" <td>An Act extending the public records law to the...</td>\n",
|
294 |
+
" <td>S2064</td>\n",
|
295 |
+
" <td>SD390</td>\n",
|
296 |
+
" <td>\\tSECTION 1. Section 7 of chapter 4 of the Gen...</td>\n",
|
297 |
+
" <td>[['7', '4'], ['7', '4'], ['10', '66']]</td>\n",
|
298 |
+
" </tr>\n",
|
299 |
+
" <tr>\n",
|
300 |
+
" <th>9</th>\n",
|
301 |
+
" <td>An Act to end discriminatory outcomes in vocat...</td>\n",
|
302 |
+
" <td>S257</td>\n",
|
303 |
+
" <td>SD2312</td>\n",
|
304 |
+
" <td>\\tSECTION 1. Chapter 74 of the General Laws is...</td>\n",
|
305 |
+
" <td>NaN</td>\n",
|
306 |
+
" </tr>\n",
|
307 |
+
" <tr>\n",
|
308 |
+
" <th>10</th>\n",
|
309 |
+
" <td>An Act providing affordable and accessible hig...</td>\n",
|
310 |
+
" <td>S301</td>\n",
|
311 |
+
" <td>SD667</td>\n",
|
312 |
+
" <td>\\tSECTION 1. The seventh paragraph of section ...</td>\n",
|
313 |
+
" <td>[['2', '15D'], ['2', '18B'], ['11', '15D'], ['...</td>\n",
|
314 |
+
" </tr>\n",
|
315 |
+
" <tr>\n",
|
316 |
+
" <th>11</th>\n",
|
317 |
+
" <td>An Act providing a local option for ranked cho...</td>\n",
|
318 |
+
" <td>S433</td>\n",
|
319 |
+
" <td>SD391</td>\n",
|
320 |
+
" <td>\\tSECTION 1. Section 44A of chapter 43 of the ...</td>\n",
|
321 |
+
" <td>[['77', '54']]</td>\n",
|
322 |
+
" </tr>\n",
|
323 |
+
" </tbody>\n",
|
324 |
+
"</table>\n",
|
325 |
+
"</div>"
|
326 |
+
],
|
327 |
+
"text/plain": [
|
328 |
+
" Title BillNumber DocketNumber \\\n",
|
329 |
+
"0 An Act relative to collective bargaining right... H3069 HD2435 \n",
|
330 |
+
"1 An Act relative to the open meeting law H3121 HD2204 \n",
|
331 |
+
"2 An Act relative to vehicle recalls H400 HD1240 \n",
|
332 |
+
"3 An Act providing affordable and accessible hig... H489 HD2794 \n",
|
333 |
+
"4 An Act to Improve access, opportunity, and cap... H538 HD485 \n",
|
334 |
+
"5 An Act providing a local option for ranked cho... H711 HD1183 \n",
|
335 |
+
"6 An Act establishing a jail and prison construc... S1979 SD661 \n",
|
336 |
+
"7 An Act relative to collective bargaining right... S2014 SD1208 \n",
|
337 |
+
"8 An Act extending the public records law to the... S2064 SD390 \n",
|
338 |
+
"9 An Act to end discriminatory outcomes in vocat... S257 SD2312 \n",
|
339 |
+
"10 An Act providing affordable and accessible hig... S301 SD667 \n",
|
340 |
+
"11 An Act providing a local option for ranked cho... S433 SD391 \n",
|
341 |
+
"\n",
|
342 |
+
" DocumentText \\\n",
|
343 |
+
"0 \\tSECTION 1. Section 1 of Chapter 150E of the ... \n",
|
344 |
+
"1 \\tSECTION 18 of chapter 30A of the General Law... \n",
|
345 |
+
"2 \\tSECTION 1. Chapter 90 of the General Laws, a... \n",
|
346 |
+
"3 \\tSECTION 1. The seventh paragraph of section ... \n",
|
347 |
+
"4 \\tSECTION 1. To create a new capital infrastru... \n",
|
348 |
+
"5 \\tSECTION 1. Section 44A of chapter 43 of the ... \n",
|
349 |
+
"6 \\tSECTION 1. Chapter 7C of the General Laws is... \n",
|
350 |
+
"7 \\tSECTION 1. Section 1 of chapter 150E of the ... \n",
|
351 |
+
"8 \\tSECTION 1. Section 7 of chapter 4 of the Gen... \n",
|
352 |
+
"9 \\tSECTION 1. Chapter 74 of the General Laws is... \n",
|
353 |
+
"10 \\tSECTION 1. The seventh paragraph of section ... \n",
|
354 |
+
"11 \\tSECTION 1. Section 44A of chapter 43 of the ... \n",
|
355 |
+
"\n",
|
356 |
+
" List References \n",
|
357 |
+
"0 [['1', '150E'], ['23', '268A']] \n",
|
358 |
+
"1 [['18', '30A']] \n",
|
359 |
+
"2 NaN \n",
|
360 |
+
"3 [['2', '15D'], ['2', '18B'], ['11', '15D'], ['... \n",
|
361 |
+
"4 [['10', '70B']] \n",
|
362 |
+
"5 [['77', '54']] \n",
|
363 |
+
"6 [['1', '125'], ['73', '7C']] \n",
|
364 |
+
"7 [['1', '150E'], ['23', '268A']] \n",
|
365 |
+
"8 [['7', '4'], ['7', '4'], ['10', '66']] \n",
|
366 |
+
"9 NaN \n",
|
367 |
+
"10 [['2', '15D'], ['2', '18B'], ['11', '15D'], ['... \n",
|
368 |
+
"11 [['77', '54']] "
|
369 |
+
]
|
370 |
+
},
|
371 |
+
"execution_count": 4,
|
372 |
+
"metadata": {},
|
373 |
+
"output_type": "execute_result"
|
374 |
+
}
|
375 |
+
],
|
376 |
+
"source": [
|
377 |
+
"df_cleaned = df[['Title', 'BillNumber', 'DocketNumber', 'DocumentText', 'List References']]\n",
|
378 |
+
"df_cleaned"
|
379 |
+
]
|
380 |
+
},
|
381 |
+
{
|
382 |
+
"cell_type": "code",
|
383 |
+
"execution_count": 5,
|
384 |
+
"metadata": {},
|
385 |
+
"outputs": [],
|
386 |
+
"source": [
|
387 |
+
"import ast \n",
|
388 |
+
"\n",
|
389 |
+
"new_df = df_cleaned.copy()\n",
|
390 |
+
"\n",
|
391 |
+
"new_df['List References'] = df_cleaned['List References'].apply(lambda x: \"None\" if pd.isna(x) else ast.literal_eval(x))"
|
392 |
+
]
|
393 |
+
},
|
394 |
+
{
|
395 |
+
"cell_type": "code",
|
396 |
+
"execution_count": 6,
|
397 |
+
"metadata": {},
|
398 |
+
"outputs": [
|
399 |
+
{
|
400 |
+
"data": {
|
401 |
+
"text/plain": [
|
402 |
+
"0 [[1, 150E], [23, 268A]]\n",
|
403 |
+
"1 [[18, 30A]]\n",
|
404 |
+
"2 None\n",
|
405 |
+
"3 [[2, 15D], [2, 18B], [11, 15D], [19, 66]]\n",
|
406 |
+
"4 [[10, 70B]]\n",
|
407 |
+
"5 [[77, 54]]\n",
|
408 |
+
"6 [[1, 125], [73, 7C]]\n",
|
409 |
+
"7 [[1, 150E], [23, 268A]]\n",
|
410 |
+
"8 [[7, 4], [7, 4], [10, 66]]\n",
|
411 |
+
"9 None\n",
|
412 |
+
"10 [[2, 15D], [2, 18B], [11, 15D], [19, 66]]\n",
|
413 |
+
"11 [[77, 54]]\n",
|
414 |
+
"Name: List References, dtype: object"
|
415 |
+
]
|
416 |
+
},
|
417 |
+
"execution_count": 6,
|
418 |
+
"metadata": {},
|
419 |
+
"output_type": "execute_result"
|
420 |
+
}
|
421 |
+
],
|
422 |
+
"source": [
|
423 |
+
"new_df['List References']"
|
424 |
+
]
|
425 |
+
},
|
426 |
+
{
|
427 |
+
"cell_type": "code",
|
428 |
+
"execution_count": 7,
|
429 |
+
"metadata": {},
|
430 |
+
"outputs": [
|
431 |
+
{
|
432 |
+
"data": {
|
433 |
+
"text/plain": [
|
434 |
+
"[['2', '15D'], ['2', '18B'], ['11', '15D'], ['19', '66']]"
|
435 |
+
]
|
436 |
+
},
|
437 |
+
"execution_count": 7,
|
438 |
+
"metadata": {},
|
439 |
+
"output_type": "execute_result"
|
440 |
+
}
|
441 |
+
],
|
442 |
+
"source": [
|
443 |
+
"new_df['List References'].values[3]"
|
444 |
+
]
|
445 |
+
},
|
446 |
+
{
|
447 |
+
"cell_type": "code",
|
448 |
+
"execution_count": 8,
|
449 |
+
"metadata": {},
|
450 |
+
"outputs": [],
|
451 |
+
"source": [
|
452 |
+
"import numpy as np\n",
|
453 |
+
"\n",
|
454 |
+
"def make_api_call(item):\n",
|
455 |
+
" result = \"\"\"\"\"\"\n",
|
456 |
+
" try:\n",
|
457 |
+
" # unpack section and chapter for example: ['2', '15D']\n",
|
458 |
+
" section, chapter = item\n",
|
459 |
+
" r = requests.get(f'https://malegislature.gov/api/Chapters/{chapter}/Sections/{section}', verify=False)\n",
|
460 |
+
" r = r.json()\n",
|
461 |
+
"\n",
|
462 |
+
" # fields to extract\n",
|
463 |
+
" result = r.get(\"Text\", np.nan)\n",
|
464 |
+
" return result\n",
|
465 |
+
" except:\n",
|
466 |
+
" pass"
|
467 |
+
]
|
468 |
+
},
|
469 |
+
{
|
470 |
+
"cell_type": "code",
|
471 |
+
"execution_count": 10,
|
472 |
+
"metadata": {},
|
473 |
+
"outputs": [
|
474 |
+
{
|
475 |
+
"name": "stderr",
|
476 |
+
"output_type": "stream",
|
477 |
+
"text": [
|
478 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
479 |
+
" warnings.warn(\n",
|
480 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
481 |
+
" warnings.warn(\n",
|
482 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
483 |
+
" warnings.warn(\n"
|
484 |
+
]
|
485 |
+
},
|
486 |
+
{
|
487 |
+
"name": "stdout",
|
488 |
+
"output_type": "stream",
|
489 |
+
"text": [
|
490 |
+
"Section 2. There shall be in the executive office of education a department of early education and care, in this chapter called the department, which shall be the state agency responsible for compliance with early education and care services under the Personal Responsibility and Work Opportunity Reconciliation Act of 1996 (Pub. L. 104–193), or any successor federal statute. The department shall be the state education agency for the purposes of early education and care services under federal law. The department shall seek, apply for and encourage the use of any federal funds for early education and care services, and shall facilitate the coordination of federal, state, and local policies concerning early education and care. The department shall be under the supervision and management of the commissioner of early education and care, in this chapter called the commissioner. \n",
|
491 |
+
"\n",
|
492 |
+
"The department shall:— \n",
|
493 |
+
"\n",
|
494 |
+
"(a) be the lead agency of the commonwealth for administering and providing early education and care programs and services to children; \n",
|
495 |
+
"\n",
|
496 |
+
"(b) provide early education and care programs and mental health consultation and other support services for children in the commonwealth through grants, contracting for those programs and services, and providing vouchers to participants, and promote the coordination of all such programs and services; \n",
|
497 |
+
"\n",
|
498 |
+
"(c) license or approve child care centers, school-aged child care programs, family child care homes and large family child care homes, family foster care which is not supervised and approved by a placement agency, placement agencies, group care facilities, or temporary shelter facilities; \n",
|
499 |
+
"\n",
|
500 |
+
"(d) develop and maintain a current consolidated waiting list for all subsidized early education and care programs, and services in the commonwealth; \n",
|
501 |
+
"\n",
|
502 |
+
"(e) establish and develop a schedule for revising: (1) a rate structure for voucher and contracted payments to providers of subsidized early education and care programs and services on behalf of low-income and other at-risk children; and (2) a sliding fee scale for participants in those programs. A public hearing under chapter 30A and the approval of the board shall be required before the establishment or revision of the rate structure and sliding fee scale; \n",
|
503 |
+
"\n",
|
504 |
+
"(f) manage and implement the Massachusetts universal pre-kindergarten program, established in section 13, that may be phased in over a period of time as determined by the board, and ensure the universal accessibility to the program by using the sliding fee scale developed for early education and care programs; \n",
|
505 |
+
"\n",
|
506 |
+
"(g) after a public hearing, adopt criteria including income eligibility requirements, for determining eligibility for an early education and care program or service, including the universal pre-kindergarten program under this chapter and develop a schedule for revising such criteria. Income eligibility requirements shall include a maximum allowable income for working families; \n",
|
507 |
+
"\n",
|
508 |
+
"(h) monitor and evaluate on an ongoing basis all early education and care programs and services, including program outcomes in meeting the developmental and educational needs of all children; \n",
|
509 |
+
"\n",
|
510 |
+
"(i) analyze and evaluate all budget requests for early education and care programs and services, including requests from secretaries, departments, agencies, or other offices within the commonwealth and make recommendations to the secretary of education, general court, appropriate secretaries, departments, agencies, or other offices regarding coordination and approval of those budget requests; \n",
|
511 |
+
"\n",
|
512 |
+
"(j) lease, purchase, hold and dispose of personal and real property it considers necessary to carry out this chapter; \n",
|
513 |
+
"\n",
|
514 |
+
"(k) seek to increase the availability of early education and care programs and services and encourage all providers of those programs and services to work together to create an array of options allowing families to select programs that fit with their schedules; \n",
|
515 |
+
"\n",
|
516 |
+
"(l) provide information and referral to persons seeking early education and care programs and services; \n",
|
517 |
+
"\n",
|
518 |
+
"(m) work in conjunction with the department of transitional assistance to obtain federal reimbursement under the federal Social Security Act for all participants in publicly-funded early education and care programs and services who are eligible; \n",
|
519 |
+
"\n",
|
520 |
+
"(n) promote the development of early education and care services for children by seeking and accepting federal grants as well as assisting other agencies of the commonwealth and local agencies to take full advantage of all federal funds available for those services; \n",
|
521 |
+
"\n",
|
522 |
+
"(o) provide technical assistance and consultation to providers and potential providers of early education and care services; \n",
|
523 |
+
"\n",
|
524 |
+
"(p) facilitate the development of the early education and care workforce, and, when appropriate, provide for training programs and professional development for persons offering early education and care programs and services; \n",
|
525 |
+
"\n",
|
526 |
+
"(q) establish and regularly update: (1) a comprehensive database of early childhood educators and providers, hereinafter referred to as the educator database, for the purpose of enhancing the workforce development system; and (2) a comprehensive database of children both waiting for and receiving early education and care services, in this chapter called the student database, that is compatible with relevant databases at the department of elementary and secondary education and the executive office of health and human services; and \n",
|
527 |
+
"\n",
|
528 |
+
"(r) collect and disseminate information to assist parents in nurturing their children's development and education. This information shall be made widely available in written form and accessible through the department's website, in English and other commonly spoken languages in the commonwealth. \n",
|
529 |
+
"\n",
|
530 |
+
"(s) plan for and address the unique needs of families with infants and toddlers, including providing parent education, early literacy services and meaningful opportunities for families not enrolled in early education and care to support their children's development. \n",
|
531 |
+
"\n",
|
532 |
+
"(t) subject to appropriation, provide consultation services and workforce development to meet the behavioral health needs of children in early education and care programs, giving preference to those services designed to prevent expulsions and suspensions. \n",
|
533 |
+
"\n",
|
534 |
+
"(u) subject to appropriation and notwithstanding any general or special law to the contrary, assure quality early education and care provided to children through family child care providers by working cooperatively with family child care providers to build upon the existing system and continuously improve the delivery of high quality early education and care services for eligible low income families through providers who have the requisite skills and training. \n",
|
535 |
+
"\n",
|
536 |
+
"Section 2. The department shall provide and administer a comprehensive child welfare program for children and families, including the following services:— \n",
|
537 |
+
"\n",
|
538 |
+
"(1) casework or counseling, including services to families, foster families or individuals; \n",
|
539 |
+
"\n",
|
540 |
+
"(2) protective services for children; \n",
|
541 |
+
"\n",
|
542 |
+
"(3) legal services for families, children or individuals who are clients of the department; \n",
|
543 |
+
"\n",
|
544 |
+
"(4) adoption services; \n",
|
545 |
+
"\n",
|
546 |
+
"(5) information and referral services; \n",
|
547 |
+
"\n",
|
548 |
+
"(6) foster family care for children and specialized foster family care for children with special needs; \n",
|
549 |
+
"\n",
|
550 |
+
"(7) residential care for children with special needs who are not suited for foster family care or specialized foster family care; \n",
|
551 |
+
"\n",
|
552 |
+
"(8) informal education and group activities; \n",
|
553 |
+
"\n",
|
554 |
+
"(9) training in parenthood and home management for parents, foster parents and prospective parents; \n",
|
555 |
+
"\n",
|
556 |
+
"(10) family services intended to prevent the need for foster care and services to children in foster care; \n",
|
557 |
+
"\n",
|
558 |
+
"(11) temporary residential programs providing counseling and supportive assistance for families in transition and their children who, because of domestic violence, homelessness, or other situations, require temporary shelter and assistance; \n",
|
559 |
+
"\n",
|
560 |
+
"(12) camping services; \n",
|
561 |
+
"\n",
|
562 |
+
"(13) information and referral services; \n",
|
563 |
+
"\n",
|
564 |
+
"(14) services for families and individuals in emergency and transitional housing; \n",
|
565 |
+
"\n",
|
566 |
+
"(15) comprehensive youth development services; \n",
|
567 |
+
"\n",
|
568 |
+
"(16) access to and coordination of medical, dental and mental health services for children in foster care whose families are receiving services from other state agencies; and \n",
|
569 |
+
"\n",
|
570 |
+
"(17) child care placements for children whose families have an open case with the department. \n",
|
571 |
+
"\n",
|
572 |
+
"Section 11. The board, after holding a public hearing, shall adopt, and develop a schedule for revising, program quality standards and requirements that any early education and care program or provider shall meet. The department shall develop separate but related standards for children in the following developmental stages: infant and toddler, pre-school, early elementary and older school-age; and for additional developmental stages that the department may determine relevant based on research and best practices. These standards and requirements shall incorporate essential elements of high-quality early education and care that promote healthy, cognitive, linguistic, social, emotional and physical outcomes, and school readiness based on curriculum frameworks. Standards and requirements shall build upon the licensure regulations promulgated under section 8. \n",
|
573 |
+
"\n",
|
574 |
+
"(a) The standards for all developmental stages and any succeeding developmental stages adopted by the department shall be incorporated into a single document and linked by a common philosophy and consistent goals and guiding principles. This document shall also include the policy developed jointly with the department and board of elementary and secondary education required under section 13 to ensure smooth transitions between infant and toddler programs, preschool and kindergarten. The standards shall be regularly updated to reflect applicable research and best practices. The board shall submit standards and requirements, or revisions of them, to the joint committee on education and the house and senate committees on ways and means at least 60 days before adoption. The joint committee on education shall review and comment on the rules and regulations during that time period. \n",
|
575 |
+
"\n",
|
576 |
+
"(b) The board shall include, in its adoption and revision of program quality standards, a specific focus on the unique requirements and needs of preschool-aged children including, but not limited to, rigorous guidelines for preschool learning experiences. Every early education and care program or provider shall be required to meet these standards in order to participate in the Massachusetts universal pre-kindergarten program, established in section 13. \n",
|
577 |
+
"\n",
|
578 |
+
"(c) The department, with approval of the board, shall develop a consistent set of learning standards for all preschool programs in the commonwealth, to be included in the program quality standards. The standards shall be consistent with the curriculum frameworks developed by the department of elementary and secondary education, shall be research-based and shall be updated regularly to reflect best practices in the field of early education and care. The standards shall guarantee, at a minimum, that every program participating in the Massachusetts universal pre-kindergarten program shall include consultation and intervention services for children at risk for expulsion. \n",
|
579 |
+
"\n",
|
580 |
+
"(d) With the approval of the board, the department shall develop and establish a schedule for revising a comprehensive set of developmental benchmarks which may be incorporated into the quality standards, and which may be used by all early education and care programs in measuring children's developmental progress utilizing the healthy, cognitive, linguistic, social, emotional and physical outcomes for developing the quality standards. In developing the benchmarks, the department shall collaborate with pediatricians, child psychologists, and researchers within the field of child development and developmental psychology, in order to ensure that the document reflects best practices in the field and the most recent evidence provided by science relative to early childhood development. \n",
|
581 |
+
"\n",
|
582 |
+
"Section 19. (a) When designing or acquiring an electronic record keeping system or database, records access officers shall, consistent with section 17 of chapter 110G, consult with their chief executive officer, chief administrative officer or the Massachusetts office of information technology pursuant to chapter 7D to ensure, to the extent feasible, that the system or database is capable of providing data in a commonly available electronic, machine readable format. Such database designs or acquisitions shall allow for, to the extent feasible, information storage and retrieval methods that permit the segregation and retrieval of public records and redacting of exempt information in order to provide maximum public access. No agency or municipality shall enter into a contract for the storage of electronic records containing public records if the contract prevents or unduly restricts the records access officer from providing the public records in accordance with this chapter. \n",
|
583 |
+
"\n",
|
584 |
+
"(b) Every agency shall provide on a searchable website electronic copies, accessible in a commonly available electronic format, of the following types of records, provided that any agency may withhold any record or portion thereof in accordance with state or federal law: \n",
|
585 |
+
"\n",
|
586 |
+
"(i) final opinions, decisions, orders, or votes from agency proceedings; \n",
|
587 |
+
"\n",
|
588 |
+
"(ii) annual reports; \n",
|
589 |
+
"\n",
|
590 |
+
"(iii) notices of regulations proposed under chapter 30A; \n",
|
591 |
+
"\n",
|
592 |
+
"(iv) notices of hearings; \n",
|
593 |
+
"\n",
|
594 |
+
"(v) winning bids for public contracts; \n",
|
595 |
+
"\n",
|
596 |
+
"(vi) awards of federal, state and municipal government grants; \n",
|
597 |
+
"\n",
|
598 |
+
"(vii) minutes of open meetings; \n",
|
599 |
+
"\n",
|
600 |
+
"(viii) agency budgets; and \n",
|
601 |
+
"\n",
|
602 |
+
"(ix) any public record information of significant interest that the agency deems appropriate to post. \n",
|
603 |
+
"\n",
|
604 |
+
"\n",
|
605 |
+
"14007\n"
|
606 |
+
]
|
607 |
+
},
|
608 |
+
{
|
609 |
+
"name": "stderr",
|
610 |
+
"output_type": "stream",
|
611 |
+
"text": [
|
612 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
613 |
+
" warnings.warn(\n"
|
614 |
+
]
|
615 |
+
}
|
616 |
+
],
|
617 |
+
"source": [
|
618 |
+
"sample_1 = new_df['List References'].values[3]\n",
|
619 |
+
"\n",
|
620 |
+
"result = \"\"\"\"\"\"\n",
|
621 |
+
"# Storing and printing each pair\n",
|
622 |
+
"formatted_data = []\n",
|
623 |
+
"for pair in sample_1:\n",
|
624 |
+
" string = make_api_call(pair)\n",
|
625 |
+
" result += string\n",
|
626 |
+
" \n",
|
627 |
+
"\n",
|
628 |
+
"print(result)\n",
|
629 |
+
"print(len(result))"
|
630 |
+
]
|
631 |
+
},
|
632 |
+
{
|
633 |
+
"cell_type": "markdown",
|
634 |
+
"metadata": {},
|
635 |
+
"source": [
|
636 |
+
"this is in the format of section, chapter"
|
637 |
+
]
|
638 |
+
},
|
639 |
+
{
|
640 |
+
"cell_type": "code",
|
641 |
+
"execution_count": 11,
|
642 |
+
"metadata": {},
|
643 |
+
"outputs": [
|
644 |
+
{
|
645 |
+
"name": "stderr",
|
646 |
+
"output_type": "stream",
|
647 |
+
"text": [
|
648 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
649 |
+
" warnings.warn(\n",
|
650 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
651 |
+
" warnings.warn(\n",
|
652 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
653 |
+
" warnings.warn(\n",
|
654 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
655 |
+
" warnings.warn(\n",
|
656 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
657 |
+
" warnings.warn(\n",
|
658 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
659 |
+
" warnings.warn(\n",
|
660 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
661 |
+
" warnings.warn(\n",
|
662 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
663 |
+
" warnings.warn(\n",
|
664 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
665 |
+
" warnings.warn(\n",
|
666 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
667 |
+
" warnings.warn(\n",
|
668 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
669 |
+
" warnings.warn(\n",
|
670 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
671 |
+
" warnings.warn(\n",
|
672 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
673 |
+
" warnings.warn(\n",
|
674 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
675 |
+
" warnings.warn(\n",
|
676 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
677 |
+
" warnings.warn(\n",
|
678 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
679 |
+
" warnings.warn(\n",
|
680 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
681 |
+
" warnings.warn(\n",
|
682 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
683 |
+
" warnings.warn(\n",
|
684 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
685 |
+
" warnings.warn(\n",
|
686 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
687 |
+
" warnings.warn(\n",
|
688 |
+
"c:\\Users\\16178\\anaconda3\\envs\\maple\\Lib\\site-packages\\urllib3\\connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'malegislature.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n",
|
689 |
+
" warnings.warn(\n"
|
690 |
+
]
|
691 |
+
}
|
692 |
+
],
|
693 |
+
"source": [
|
694 |
+
"new_df['MGL'] = new_df['List References'].apply(lambda pairs: [make_api_call(item) for item in pairs if item is not None])"
|
695 |
+
]
|
696 |
+
},
|
697 |
+
{
|
698 |
+
"cell_type": "code",
|
699 |
+
"execution_count": 32,
|
700 |
+
"metadata": {},
|
701 |
+
"outputs": [
|
702 |
+
{
|
703 |
+
"data": {
|
704 |
+
"text/plain": [
|
705 |
+
"Title An Act providing affordable and accessible hig...\n",
|
706 |
+
"BillNumber H489\n",
|
707 |
+
"DocketNumber HD2794\n",
|
708 |
+
"DocumentText \\tSECTION 1. The seventh paragraph of section ...\n",
|
709 |
+
"List References [[2, 15D], [2, 18B], [11, 15D], [19, 66]]\n",
|
710 |
+
"MGL [Section 2. There shall be in the executive of...\n",
|
711 |
+
"Name: 3, dtype: object"
|
712 |
+
]
|
713 |
+
},
|
714 |
+
"execution_count": 32,
|
715 |
+
"metadata": {},
|
716 |
+
"output_type": "execute_result"
|
717 |
+
}
|
718 |
+
],
|
719 |
+
"source": [
|
720 |
+
"new_df.iloc[3]"
|
721 |
+
]
|
722 |
+
},
|
723 |
+
{
|
724 |
+
"cell_type": "code",
|
725 |
+
"execution_count": 33,
|
726 |
+
"metadata": {},
|
727 |
+
"outputs": [
|
728 |
+
{
|
729 |
+
"data": {
|
730 |
+
"text/plain": [
|
731 |
+
"[\"Section 2. There shall be in the executive office of education a department of early education and care, in this chapter called the department, which shall be the state agency responsible for compliance with early education and care services under the Personal Responsibility and Work Opportunity Reconciliation Act of 1996 (Pub. L. 104–193), or any successor federal statute. The department shall be the state education agency for the purposes of early education and care services under federal law. The department shall seek, apply for and encourage the use of any federal funds for early education and care services, and shall facilitate the coordination of federal, state, and local policies concerning early education and care. The department shall be under the supervision and management of the commissioner of early education and care, in this chapter called the commissioner. \\r\\n\\r\\nThe department shall:— \\r\\n\\r\\n(a) be the lead agency of the commonwealth for administering and providing early education and care programs and services to children; \\r\\n\\r\\n(b) provide early education and care programs and mental health consultation and other support services for children in the commonwealth through grants, contracting for those programs and services, and providing vouchers to participants, and promote the coordination of all such programs and services; \\r\\n\\r\\n(c) license or approve child care centers, school-aged child care programs, family child care homes and large family child care homes, family foster care which is not supervised and approved by a placement agency, placement agencies, group care facilities, or temporary shelter facilities; \\r\\n\\r\\n(d) develop and maintain a current consolidated waiting list for all subsidized early education and care programs, and services in the commonwealth; \\r\\n\\r\\n(e) establish and develop a schedule for revising: (1) a rate structure for voucher and contracted payments to providers of subsidized early education and care programs and services on behalf of low-income and other at-risk children; and (2) a sliding fee scale for participants in those programs. A public hearing under chapter 30A and the approval of the board shall be required before the establishment or revision of the rate structure and sliding fee scale; \\r\\n\\r\\n(f) manage and implement the Massachusetts universal pre-kindergarten program, established in section 13, that may be phased in over a period of time as determined by the board, and ensure the universal accessibility to the program by using the sliding fee scale developed for early education and care programs; \\r\\n\\r\\n(g) after a public hearing, adopt criteria including income eligibility requirements, for determining eligibility for an early education and care program or service, including the universal pre-kindergarten program under this chapter and develop a schedule for revising such criteria. Income eligibility requirements shall include a maximum allowable income for working families; \\r\\n\\r\\n(h) monitor and evaluate on an ongoing basis all early education and care programs and services, including program outcomes in meeting the developmental and educational needs of all children; \\r\\n\\r\\n(i) analyze and evaluate all budget requests for early education and care programs and services, including requests from secretaries, departments, agencies, or other offices within the commonwealth and make recommendations to the secretary of education, general court, appropriate secretaries, departments, agencies, or other offices regarding coordination and approval of those budget requests; \\r\\n\\r\\n(j) lease, purchase, hold and dispose of personal and real property it considers necessary to carry out this chapter; \\r\\n\\r\\n(k) seek to increase the availability of early education and care programs and services and encourage all providers of those programs and services to work together to create an array of options allowing families to select programs that fit with their schedules; \\r\\n\\r\\n(l) provide information and referral to persons seeking early education and care programs and services; \\r\\n\\r\\n(m) work in conjunction with the department of transitional assistance to obtain federal reimbursement under the federal Social Security Act for all participants in publicly-funded early education and care programs and services who are eligible; \\r\\n\\r\\n(n) promote the development of early education and care services for children by seeking and accepting federal grants as well as assisting other agencies of the commonwealth and local agencies to take full advantage of all federal funds available for those services; \\r\\n\\r\\n(o) provide technical assistance and consultation to providers and potential providers of early education and care services; \\r\\n\\r\\n(p) facilitate the development of the early education and care workforce, and, when appropriate, provide for training programs and professional development for persons offering early education and care programs and services; \\r\\n\\r\\n(q) establish and regularly update: (1) a comprehensive database of early childhood educators and providers, hereinafter referred to as the educator database, for the purpose of enhancing the workforce development system; and (2) a comprehensive database of children both waiting for and receiving early education and care services, in this chapter called the student database, that is compatible with relevant databases at the department of elementary and secondary education and the executive office of health and human services; and \\r\\n\\r\\n(r) collect and disseminate information to assist parents in nurturing their children's development and education. This information shall be made widely available in written form and accessible through the department's website, in English and other commonly spoken languages in the commonwealth. \\r\\n\\r\\n(s) plan for and address the unique needs of families with infants and toddlers, including providing parent education, early literacy services and meaningful opportunities for families not enrolled in early education and care to support their children's development. \\r\\n\\r\\n(t) subject to appropriation, provide consultation services and workforce development to meet the behavioral health needs of children in early education and care programs, giving preference to those services designed to prevent expulsions and suspensions. \\r\\n\\r\\n(u) subject to appropriation and notwithstanding any general or special law to the contrary, assure quality early education and care provided to children through family child care providers by working cooperatively with family child care providers to build upon the existing system and continuously improve the delivery of high quality early education and care services for eligible low income families through providers who have the requisite skills and training. \\r\\n\\r\\n\",\n",
|
732 |
+
" 'Section 2. The department shall provide and administer a comprehensive child welfare program for children and families, including the following services:— \\r\\n\\r\\n(1) casework or counseling, including services to families, foster families or individuals; \\r\\n\\r\\n(2) protective services for children; \\r\\n\\r\\n(3) legal services for families, children or individuals who are clients of the department; \\r\\n\\r\\n(4) adoption services; \\r\\n\\r\\n(5) information and referral services; \\r\\n\\r\\n(6) foster family care for children and specialized foster family care for children with special needs; \\r\\n\\r\\n(7) residential care for children with special needs who are not suited for foster family care or specialized foster family care; \\r\\n\\r\\n(8) informal education and group activities; \\r\\n\\r\\n(9) training in parenthood and home management for parents, foster parents and prospective parents; \\r\\n\\r\\n(10) family services intended to prevent the need for foster care and services to children in foster care; \\r\\n\\r\\n(11) temporary residential programs providing counseling and supportive assistance for families in transition and their children who, because of domestic violence, homelessness, or other situations, require temporary shelter and assistance; \\r\\n\\r\\n(12) camping services; \\r\\n\\r\\n(13) information and referral services; \\r\\n\\r\\n(14) services for families and individuals in emergency and transitional housing; \\r\\n\\r\\n(15) comprehensive youth development services; \\r\\n\\r\\n(16) access to and coordination of medical, dental and mental health services for children in foster care whose families are receiving services from other state agencies; and \\r\\n\\r\\n(17) child care placements for children whose families have an open case with the department. \\r\\n\\r\\n',\n",
|
733 |
+
" \"Section 11. The board, after holding a public hearing, shall adopt, and develop a schedule for revising, program quality standards and requirements that any early education and care program or provider shall meet. The department shall develop separate but related standards for children in the following developmental stages: infant and toddler, pre-school, early elementary and older school-age; and for additional developmental stages that the department may determine relevant based on research and best practices. These standards and requirements shall incorporate essential elements of high-quality early education and care that promote healthy, cognitive, linguistic, social, emotional and physical outcomes, and school readiness based on curriculum frameworks. Standards and requirements shall build upon the licensure regulations promulgated under section 8. \\r\\n\\r\\n(a) The standards for all developmental stages and any succeeding developmental stages adopted by the department shall be incorporated into a single document and linked by a common philosophy and consistent goals and guiding principles. This document shall also include the policy developed jointly with the department and board of elementary and secondary education required under section 13 to ensure smooth transitions between infant and toddler programs, preschool and kindergarten. The standards shall be regularly updated to reflect applicable research and best practices. The board shall submit standards and requirements, or revisions of them, to the joint committee on education and the house and senate committees on ways and means at least 60 days before adoption. The joint committee on education shall review and comment on the rules and regulations during that time period. \\r\\n\\r\\n(b) The board shall include, in its adoption and revision of program quality standards, a specific focus on the unique requirements and needs of preschool-aged children including, but not limited to, rigorous guidelines for preschool learning experiences. Every early education and care program or provider shall be required to meet these standards in order to participate in the Massachusetts universal pre-kindergarten program, established in section 13. \\r\\n\\r\\n(c) The department, with approval of the board, shall develop a consistent set of learning standards for all preschool programs in the commonwealth, to be included in the program quality standards. The standards shall be consistent with the curriculum frameworks developed by the department of elementary and secondary education, shall be research-based and shall be updated regularly to reflect best practices in the field of early education and care. The standards shall guarantee, at a minimum, that every program participating in the Massachusetts universal pre-kindergarten program shall include consultation and intervention services for children at risk for expulsion. \\r\\n\\r\\n(d) With the approval of the board, the department shall develop and establish a schedule for revising a comprehensive set of developmental benchmarks which may be incorporated into the quality standards, and which may be used by all early education and care programs in measuring children's developmental progress utilizing the healthy, cognitive, linguistic, social, emotional and physical outcomes for developing the quality standards. In developing the benchmarks, the department shall collaborate with pediatricians, child psychologists, and researchers within the field of child development and developmental psychology, in order to ensure that the document reflects best practices in the field and the most recent evidence provided by science relative to early childhood development. \\r\\n\\r\\n\",\n",
|
734 |
+
" 'Section 19. (a) When designing or acquiring an electronic record keeping system or database, records access officers shall, consistent with section 17 of chapter 110G, consult with their chief executive officer, chief administrative officer or the Massachusetts office of information technology pursuant to chapter 7D to ensure, to the extent feasible, that the system or database is capable of providing data in a commonly available electronic, machine readable format. Such database designs or acquisitions shall allow for, to the extent feasible, information storage and retrieval methods that permit the segregation and retrieval of public records and redacting of exempt information in order to provide maximum public access. No agency or municipality shall enter into a contract for the storage of electronic records containing public records if the contract prevents or unduly restricts the records access officer from providing the public records in accordance with this chapter. \\r\\n\\r\\n(b) Every agency shall provide on a searchable website electronic copies, accessible in a commonly available electronic format, of the following types of records, provided that any agency may withhold any record or portion thereof in accordance with state or federal law: \\r\\n\\r\\n(i) final opinions, decisions, orders, or votes from agency proceedings; \\r\\n\\r\\n(ii) annual reports; \\r\\n\\r\\n(iii) notices of regulations proposed under chapter 30A; \\r\\n\\r\\n(iv) notices of hearings; \\r\\n\\r\\n(v) winning bids for public contracts; \\r\\n\\r\\n(vi) awards of federal, state and municipal government grants; \\r\\n\\r\\n(vii) minutes of open meetings; \\r\\n\\r\\n(viii) agency budgets; and \\r\\n\\r\\n(ix) any public record information of significant interest that the agency deems appropriate to post. \\r\\n\\r\\n']"
|
735 |
+
]
|
736 |
+
},
|
737 |
+
"execution_count": 33,
|
738 |
+
"metadata": {},
|
739 |
+
"output_type": "execute_result"
|
740 |
+
}
|
741 |
+
],
|
742 |
+
"source": [
|
743 |
+
"new_df['MGL'].values[3]"
|
744 |
+
]
|
745 |
+
},
|
746 |
+
{
|
747 |
+
"cell_type": "code",
|
748 |
+
"execution_count": 40,
|
749 |
+
"metadata": {},
|
750 |
+
"outputs": [],
|
751 |
+
"source": [
|
752 |
+
"new_df['combined_MGL'] = new_df['MGL'].apply(lambda lst: ' '.join([str(item) for item in lst if item is not None]))"
|
753 |
+
]
|
754 |
+
},
|
755 |
+
{
|
756 |
+
"cell_type": "code",
|
757 |
+
"execution_count": 43,
|
758 |
+
"metadata": {},
|
759 |
+
"outputs": [],
|
760 |
+
"source": [
|
761 |
+
"new_df['length_MGL'] = new_df['combined_MGL'].apply(lambda x: len(x) if x else None)"
|
762 |
+
]
|
763 |
+
},
|
764 |
+
{
|
765 |
+
"cell_type": "code",
|
766 |
+
"execution_count": 44,
|
767 |
+
"metadata": {},
|
768 |
+
"outputs": [
|
769 |
+
{
|
770 |
+
"data": {
|
771 |
+
"text/plain": [
|
772 |
+
"0 12170.0\n",
|
773 |
+
"1 4047.0\n",
|
774 |
+
"2 NaN\n",
|
775 |
+
"3 14010.0\n",
|
776 |
+
"4 5565.0\n",
|
777 |
+
"5 680.0\n",
|
778 |
+
"6 2813.0\n",
|
779 |
+
"7 12170.0\n",
|
780 |
+
"8 78184.0\n",
|
781 |
+
"9 NaN\n",
|
782 |
+
"10 14010.0\n",
|
783 |
+
"11 680.0\n",
|
784 |
+
"Name: length_MGL, dtype: float64"
|
785 |
+
]
|
786 |
+
},
|
787 |
+
"execution_count": 44,
|
788 |
+
"metadata": {},
|
789 |
+
"output_type": "execute_result"
|
790 |
+
}
|
791 |
+
],
|
792 |
+
"source": [
|
793 |
+
"new_df['length_MGL']"
|
794 |
+
]
|
795 |
+
},
|
796 |
+
{
|
797 |
+
"cell_type": "code",
|
798 |
+
"execution_count": 46,
|
799 |
+
"metadata": {},
|
800 |
+
"outputs": [],
|
801 |
+
"source": [
|
802 |
+
"new_df.to_csv(\"12billswith.csv\")"
|
803 |
+
]
|
804 |
+
}
|
805 |
+
],
|
806 |
+
"metadata": {
|
807 |
+
"kernelspec": {
|
808 |
+
"display_name": "maple",
|
809 |
+
"language": "python",
|
810 |
+
"name": "python3"
|
811 |
+
},
|
812 |
+
"language_info": {
|
813 |
+
"codemirror_mode": {
|
814 |
+
"name": "ipython",
|
815 |
+
"version": 3
|
816 |
+
},
|
817 |
+
"file_extension": ".py",
|
818 |
+
"mimetype": "text/x-python",
|
819 |
+
"name": "python",
|
820 |
+
"nbconvert_exporter": "python",
|
821 |
+
"pygments_lexer": "ipython3",
|
822 |
+
"version": "3.11.5"
|
823 |
+
}
|
824 |
+
},
|
825 |
+
"nbformat": 4,
|
826 |
+
"nbformat_minor": 2
|
827 |
+
}
|
demoapp/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Guideline to run the DemoApp using Streamlit
|
2 |
+
|
3 |
+
Using Anaconda or create an environment to run streamlit
|
4 |
+
* Create env:
|
5 |
+
```python3 -m venv env```
|
6 |
+
```source ./env/bin/activate```
|
7 |
+
* Using Anaconda:
|
8 |
+
```conda create -n maple python=3.11.5```
|
9 |
+
```conda activate maple```
|
10 |
+
|
11 |
+
In the file "app.py" in "demoapp" folder:
|
12 |
+
* ```pip install streamlit```
|
13 |
+
* Install all imported libraries: ```pip install pandas langchain openai chromadb tiktoken``` or you can refer to the requirement.txt
|
14 |
+
* ```streamlit run demoapp/app2.py```
|
15 |
+
(The "app2.py" is our work on the most popular 12 bills. It is our latest code with RAG, vectara.)
|
16 |
+
|
17 |
+
# Additional Pointers (Source:Research Paper)
|
18 |
+
In the demo app itself we have included evaluation metrics that help gauge the quality of the generated summaries in our use-case
|
19 |
+
* The metrics we have used are : ROUGE-L, ROUGE-1, ROUGE-2, Cosine Similarity, and Factual Consistency Score.
|
20 |
+
* ROUGE-1 is the the overlap of unigrams (each word) between the original bill and generated summaries.
|
21 |
+
* ROUGE-2 is the overlap of bigrams between the original bill and generated summaries.
|
22 |
+
* ROUGE-L tell us about the Longest common subsequence, taking into account sentence-level structure similarity naturally and helps identify longest co-occurring in sequence n-grams.
|
23 |
+
* Cosine Similarity in this case tells us about the text similarity of two documents.
|
24 |
+
* Factual Consistency Score: We used Vectara that trained transformer model to output probability from 0 to 1 by comparing the source and summary. 0 being hallucination, 1 being factually consistent.
|
25 |
+
|
26 |
+
# Understand this folder
|
27 |
+
extracted_mgl.txt is the relevant mgl content for the 12 bills that MAPLE team wanted. Extracted from the column using the csv files <b> 12billswithmgl.csv </b>
|
demoapp/all_bills.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:333981b1e35247c804711f8d456ffd1eb6b2c9e75b38f51639cc051f5c6d064b
|
3 |
+
size 43685253
|
demoapp/app.py
ADDED
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
__import__('pysqlite3')
|
5 |
+
import sys
|
6 |
+
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
|
7 |
+
|
8 |
+
from langchain.prompts import PromptTemplate
|
9 |
+
from langchain.chains import LLMChain, create_tagging_chain, create_tagging_chain_pydantic
|
10 |
+
from langchain.vectorstores import Chroma
|
11 |
+
from langchain.chat_models import ChatOpenAI
|
12 |
+
from langchain.schema.runnable import RunnablePassthrough
|
13 |
+
from langchain.schema.output_parser import StrOutputParser
|
14 |
+
from langchain.callbacks import get_openai_callback
|
15 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
16 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
17 |
+
from rouge_score import rouge_scorer
|
18 |
+
from sentence_transformers import CrossEncoder
|
19 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
20 |
+
from langchain.text_splitter import CharacterTextSplitter
|
21 |
+
from langchain.document_loaders import TextLoader
|
22 |
+
from sidebar import *
|
23 |
+
from tagging import *
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
st.set_page_config(page_title="Summarize and Tagging MA Bills", layout='wide')
|
28 |
+
st.title('Summarize Bills')
|
29 |
+
|
30 |
+
sbar()
|
31 |
+
|
32 |
+
|
33 |
+
template = """"You are a summarizer model that summarizes legal bills and legislation. Please include the bill's main purpose, relevant key points and any amendements.
|
34 |
+
The summaries must be easy to understand and accurate based on the provided bill. I want you to summarize the legal bill and legislation.
|
35 |
+
Use the title {title} to guide your summary. Summarize the bill that reads as follows:\n{context}\n\nSummary: An Act [bill title]. This bill [key information].
|
36 |
+
"""
|
37 |
+
|
38 |
+
# model to test hallucination
|
39 |
+
# model = CrossEncoder('vectara/hallucination_evaluation_model')
|
40 |
+
|
41 |
+
# load the dataset
|
42 |
+
df = pd.read_csv("demoapp/all_bills.csv")
|
43 |
+
|
44 |
+
# Creating search bar
|
45 |
+
search_number = st.text_input("Search by Bill Number")
|
46 |
+
search_title = st.text_input("Search by Bill Title")
|
47 |
+
|
48 |
+
# Initial empty DataFrame
|
49 |
+
filtered_df = df
|
50 |
+
|
51 |
+
# Filtering based on inputs
|
52 |
+
if search_number:
|
53 |
+
filtered_df = df[df['BillNumber'].str.contains(search_number, case=False, na=False)]
|
54 |
+
if search_title:
|
55 |
+
filtered_df = df[df['Title'].str.contains(search_title, case=False, na=False)]
|
56 |
+
|
57 |
+
if not filtered_df.empty:
|
58 |
+
# Creating selectbox options safely
|
59 |
+
selectbox_options = [f"Bill #{num}: {filtered_df[filtered_df['BillNumber'] == num]['Title'].iloc[0]}"
|
60 |
+
for num in filtered_df['BillNumber'] if not filtered_df[filtered_df['BillNumber'] == num].empty]
|
61 |
+
|
62 |
+
option = st.selectbox(
|
63 |
+
'Select a Bill',
|
64 |
+
selectbox_options
|
65 |
+
)
|
66 |
+
|
67 |
+
# Extracting the bill number, title, and content from the selected option
|
68 |
+
bill_number = option.split(":")[0][6:]
|
69 |
+
bill_title = option.split(":")[1]
|
70 |
+
bill_content = filtered_df[filtered_df['BillNumber'] == bill_number]['DocumentText'].iloc[0]
|
71 |
+
|
72 |
+
else:
|
73 |
+
if search_number or search_title:
|
74 |
+
st.write("No bills found matching the search criteria.")
|
75 |
+
|
76 |
+
|
77 |
+
def generate_categories(text):
|
78 |
+
"""
|
79 |
+
generate tags and categories
|
80 |
+
parameters:
|
81 |
+
text: (string)
|
82 |
+
"""
|
83 |
+
try:
|
84 |
+
API_KEY = st.session_state["OPENAI_API_KEY"]
|
85 |
+
except Exception as e:
|
86 |
+
return st.error("Invalid [OpenAI API key](https://beta.openai.com/account/api-keys) or not found")
|
87 |
+
|
88 |
+
# LLM
|
89 |
+
category_prompt = """According to this list of category {category}.
|
90 |
+
|
91 |
+
classify this bill {context} into a closest relevant category.
|
92 |
+
|
93 |
+
Do not output a category outside from the list
|
94 |
+
"""
|
95 |
+
|
96 |
+
prompt = PromptTemplate(template=category_prompt, input_variables=["context", "category"])
|
97 |
+
|
98 |
+
|
99 |
+
llm = LLMChain(
|
100 |
+
llm = ChatOpenAI(openai_api_key=API_KEY, temperature=0, model='gpt-4'), prompt=prompt)
|
101 |
+
|
102 |
+
response = llm.predict(context = text, category = category_for_bill) # grab from tagging.py
|
103 |
+
return response
|
104 |
+
|
105 |
+
def generate_tags(category, context):
|
106 |
+
"""Function to generate tags using Retrieval Augmented Generation
|
107 |
+
"""
|
108 |
+
|
109 |
+
try:
|
110 |
+
API_KEY = st.session_state["OPENAI_API_KEY"]
|
111 |
+
os.environ['OPENAI_API_KEY'] = API_KEY
|
112 |
+
except Exception as e:
|
113 |
+
return st.error("Invalid [OpenAI API key](https://beta.openai.com/account/api-keys) or not found")
|
114 |
+
|
115 |
+
loader = TextLoader("demoapp/category.txt").load()
|
116 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
117 |
+
documents = text_splitter.split_documents(loader)
|
118 |
+
vectorstore = Chroma.from_documents(documents, OpenAIEmbeddings())
|
119 |
+
retriever = vectorstore.as_retriever()
|
120 |
+
|
121 |
+
# LLM
|
122 |
+
template = """You are a trustworthy assistant for question-answering tasks.
|
123 |
+
Use the following pieces of retrieved context to answer the question.
|
124 |
+
Question: {question}
|
125 |
+
Context: {context}
|
126 |
+
Answer:
|
127 |
+
|
128 |
+
"""
|
129 |
+
|
130 |
+
prompt = PromptTemplate.from_template(template)
|
131 |
+
llm = ChatOpenAI(openai_api_key=API_KEY, temperature=0, model='gpt-4')
|
132 |
+
|
133 |
+
rag_chain = (
|
134 |
+
{"context": retriever, "question": RunnablePassthrough()}
|
135 |
+
| prompt
|
136 |
+
| llm
|
137 |
+
| StrOutputParser()
|
138 |
+
)
|
139 |
+
query = f"""Output top 3 tags from the category {category} that is relevant to the context {context}
|
140 |
+
"""
|
141 |
+
|
142 |
+
response = rag_chain.invoke(query)
|
143 |
+
return response
|
144 |
+
|
145 |
+
|
146 |
+
def generate_response(text, title):
|
147 |
+
"""Function to generate response"""
|
148 |
+
try:
|
149 |
+
API_KEY = st.session_state['OPENAI_API_KEY']
|
150 |
+
except Exception as e:
|
151 |
+
return st.error("Invalid [OpenAI API key](https://beta.openai.com/account/api-keys) or not found")
|
152 |
+
|
153 |
+
prompt = PromptTemplate(input_variables=["context", "title"], template=template)
|
154 |
+
|
155 |
+
# Instantiate LLM model
|
156 |
+
with get_openai_callback() as cb:
|
157 |
+
llm = LLMChain(
|
158 |
+
llm = ChatOpenAI(openai_api_key=API_KEY,
|
159 |
+
temperature=0.01, model="gpt-3.5-turbo-1106"), prompt=prompt)
|
160 |
+
|
161 |
+
response = llm.predict(context=text, title=title)
|
162 |
+
return response, cb.total_tokens, cb.prompt_tokens, cb.completion_tokens, cb.total_cost
|
163 |
+
|
164 |
+
# Function to update or append to CSV
|
165 |
+
def update_csv(bill_num, title, summarized_bill, category, tag, csv_file_path):
|
166 |
+
try:
|
167 |
+
df = pd.read_csv(csv_file_path)
|
168 |
+
except FileNotFoundError:
|
169 |
+
# If the file does not exist, create a new DataFrame
|
170 |
+
df = pd.DataFrame(columns=["Bill Number", "Bill Title", "Summarized Bill", "Category", "Tags"])
|
171 |
+
|
172 |
+
mask = df["Bill Number"] == bill_num
|
173 |
+
if mask.any():
|
174 |
+
df.loc[mask, "Bill Title"] = title
|
175 |
+
df.loc[mask, "Summarized Bill"] = summarized_bill
|
176 |
+
df.loc[mask, "Category"] = category
|
177 |
+
df.loc[mask, "Tags"] = tag
|
178 |
+
else:
|
179 |
+
new_bill = pd.DataFrame([[bill_num, title, summarized_bill, category, tag]], columns=["Bill Number", "Bill Title", "Summarized Bill", "Category", "Tags"])
|
180 |
+
df = pd.concat([df, new_bill], ignore_index=True)
|
181 |
+
|
182 |
+
df.to_csv(csv_file_path, index=False)
|
183 |
+
return df
|
184 |
+
|
185 |
+
|
186 |
+
csv_file_path = "demoapp/generated_bills.csv"
|
187 |
+
|
188 |
+
answer_container = st.container()
|
189 |
+
with answer_container:
|
190 |
+
submit_button = st.button(label='Summarize')
|
191 |
+
# col1, col2, col3 = st.columns(3, gap='medium')
|
192 |
+
col1, col2, col3 = st.columns([1.5, 1.5, 1])
|
193 |
+
|
194 |
+
if submit_button:
|
195 |
+
with st.spinner("Working hard..."):
|
196 |
+
|
197 |
+
response, response_tokens, prompt_tokens, completion_tokens, response_cost = generate_response(bill_content, bill_title)
|
198 |
+
category_response = generate_categories(bill_content)
|
199 |
+
tag_response = generate_tags(category_response, bill_content)
|
200 |
+
|
201 |
+
with col1:
|
202 |
+
st.subheader(f"Original Bill: #{bill_number}")
|
203 |
+
st.write(bill_title)
|
204 |
+
st.write(bill_content)
|
205 |
+
|
206 |
+
with col2:
|
207 |
+
st.subheader("Generated Text")
|
208 |
+
st.write(response)
|
209 |
+
st.write("###")
|
210 |
+
st.write("Category:", category_response)
|
211 |
+
st.write(tag_response)
|
212 |
+
|
213 |
+
update_csv(bill_number, bill_title, response, category_response, tag_response, csv_file_path)
|
214 |
+
st.download_button(
|
215 |
+
label="Download Text",
|
216 |
+
data=pd.read_csv("demoapp/generated_bills.csv").to_csv(index=False).encode('utf-8'),
|
217 |
+
file_name='Bills_Summarization.csv',
|
218 |
+
mime='text/csv',)
|
219 |
+
|
220 |
+
with col3:
|
221 |
+
st.subheader("Evaluation Metrics")
|
222 |
+
# rouge score addition
|
223 |
+
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
|
224 |
+
rouge_scores = scorer.score(bill_content, response)
|
225 |
+
st.write(f"ROUGE-1 Score: {rouge_scores['rouge1'].fmeasure:.2f}")
|
226 |
+
st.write(f"ROUGE-2 Score: {rouge_scores['rouge2'].fmeasure:.2f}")
|
227 |
+
st.write(f"ROUGE-L Score: {rouge_scores['rougeL'].fmeasure:.2f}")
|
228 |
+
|
229 |
+
# calc cosine similarity
|
230 |
+
vectorizer = TfidfVectorizer()
|
231 |
+
tfidf_matrix = vectorizer.fit_transform([bill_content, response])
|
232 |
+
cosine_sim = cosine_similarity(tfidf_matrix[0], tfidf_matrix[1])
|
233 |
+
st.write(f"Cosine Similarity Score: {cosine_sim[0][0]:.2f}")
|
234 |
+
|
235 |
+
# # test hallucination
|
236 |
+
# scores = model.predict([
|
237 |
+
# [bill_content, response]
|
238 |
+
# ])
|
239 |
+
# score_result = float(scores[0])
|
240 |
+
# st.write(f"Factual Consistency Score: {round(score_result, 2)}")
|
241 |
+
|
242 |
+
st.write("###")
|
243 |
+
st.subheader("Token Usage")
|
244 |
+
st.write(f"Response Tokens: {response_tokens}")
|
245 |
+
st.write(f"Prompt Response: {prompt_tokens}")
|
246 |
+
st.write(f"Response Complete:{completion_tokens}")
|
247 |
+
st.write(f"Response Cost: $ {response_cost}")
|
demoapp/app2.py
ADDED
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
from langchain.prompts import PromptTemplate
|
5 |
+
from langchain.chains import LLMChain
|
6 |
+
from langchain.vectorstores import Chroma
|
7 |
+
from langchain.chat_models import ChatOpenAI
|
8 |
+
from langchain.schema.runnable import RunnablePassthrough
|
9 |
+
from langchain.schema.output_parser import StrOutputParser
|
10 |
+
from langchain.callbacks import get_openai_callback
|
11 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
12 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
13 |
+
from rouge_score import rouge_scorer
|
14 |
+
from sentence_transformers import CrossEncoder
|
15 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
16 |
+
from langchain.text_splitter import CharacterTextSplitter
|
17 |
+
from langchain.document_loaders import TextLoader
|
18 |
+
|
19 |
+
from sidebar import *
|
20 |
+
from tagging import *
|
21 |
+
|
22 |
+
|
23 |
+
st.set_page_config(page_title="Summarize and Tagging MA Bills", layout='wide')
|
24 |
+
st.title('Summarize Bills')
|
25 |
+
|
26 |
+
sbar()
|
27 |
+
|
28 |
+
|
29 |
+
# model to test hallucination
|
30 |
+
model = CrossEncoder('vectara/hallucination_evaluation_model')
|
31 |
+
|
32 |
+
# load the dataset
|
33 |
+
df = pd.read_csv("demoapp/12billswithmgl.csv")
|
34 |
+
|
35 |
+
|
36 |
+
def find_bills(bill_number, bill_title):
|
37 |
+
"""input:
|
38 |
+
args: bill_number: (str), Use the number of the bill to find its title and content
|
39 |
+
"""
|
40 |
+
bill = df[df['BillNumber'] == bill_number]['DocumentText']
|
41 |
+
|
42 |
+
try:
|
43 |
+
# Locate the index of the bill
|
44 |
+
idx = bill.index.tolist()[0]
|
45 |
+
# Locate the content and bill title of bill based on idx
|
46 |
+
content = df['DocumentText'].iloc[idx]
|
47 |
+
#bill_title = df['Title'].iloc[idx]
|
48 |
+
bill_number = df['BillNumber'].iloc[idx]
|
49 |
+
# laws
|
50 |
+
# law = df['combined_MGL'].iloc[idx]
|
51 |
+
|
52 |
+
return content, bill_title, bill_number
|
53 |
+
|
54 |
+
except Exception as e:
|
55 |
+
content = "blank"
|
56 |
+
st.error("Cannot find such bill from the source")
|
57 |
+
|
58 |
+
|
59 |
+
bills_to_select = {
|
60 |
+
'#H3121': 'An Act relative to the open meeting law',
|
61 |
+
'#S2064': 'An Act extending the public records law to the Governor and the Legislature',
|
62 |
+
'#H711': 'An Act providing a local option for ranked choice voting in municipal elections',
|
63 |
+
'#S1979': 'An Act establishing a jail and prison construction moratorium',
|
64 |
+
'#H489': 'An Act providing affordable and accessible high-quality early education and care to promote child development and well-being and support the economy in the Commonwealth',
|
65 |
+
'#S2014': 'An Act relative to collective bargaining rights for legislative employees',
|
66 |
+
'#S301': 'An Act providing affordable and accessible high quality early education and care to promote child development and well-being and support the economy in the Commonwealth',
|
67 |
+
'#H3069': 'An Act relative to collective bargaining rights for legislative employees',
|
68 |
+
'#S433': 'An Act providing a local option for ranked choice voting in municipal elections',
|
69 |
+
'#H400': 'An Act relative to vehicle recalls',
|
70 |
+
'#H538': 'An Act to Improve access, opportunity, and capacity in Massachusetts vocational-technical education',
|
71 |
+
'#S257': 'An Act to end discriminatory outcomes in vocational school admissions'
|
72 |
+
}
|
73 |
+
|
74 |
+
# Displaying the selectbox
|
75 |
+
selectbox_options = [f"{number}: {title}" for number, title in bills_to_select.items()]
|
76 |
+
option = st.selectbox(
|
77 |
+
'Select a Bill',
|
78 |
+
selectbox_options
|
79 |
+
)
|
80 |
+
|
81 |
+
# Extracting the bill number from the selected option
|
82 |
+
selected_num = option.split(":")[0][1:]
|
83 |
+
selected_title = option.split(":")[1]
|
84 |
+
|
85 |
+
# bill_content, bill_title, bill_number, masslaw = find_bills(selected_num, selected_title)
|
86 |
+
bill_content, bill_title, bill_number = find_bills(selected_num, selected_title)
|
87 |
+
|
88 |
+
|
89 |
+
def generate_categories(text):
|
90 |
+
"""
|
91 |
+
generate tags and categories
|
92 |
+
parameters:
|
93 |
+
text: (string)
|
94 |
+
"""
|
95 |
+
try:
|
96 |
+
API_KEY = st.session_state["OPENAI_API_KEY"]
|
97 |
+
except Exception as e:
|
98 |
+
return st.error("Invalid [OpenAI API key](https://beta.openai.com/account/api-keys) or not found")
|
99 |
+
|
100 |
+
# LLM
|
101 |
+
category_prompt = """According to this list of category {category}.
|
102 |
+
|
103 |
+
classify this bill {context} into a closest relevant category.
|
104 |
+
|
105 |
+
Do not output a category outside from the list
|
106 |
+
"""
|
107 |
+
|
108 |
+
prompt = PromptTemplate(template=category_prompt, input_variables=["context", "category"])
|
109 |
+
|
110 |
+
|
111 |
+
llm = LLMChain(
|
112 |
+
llm = ChatOpenAI(openai_api_key=API_KEY, temperature=0, model='gpt-4'), prompt=prompt)
|
113 |
+
|
114 |
+
response = llm.predict(context = text, category = category_for_bill) # grab from tagging.py
|
115 |
+
return response
|
116 |
+
|
117 |
+
|
118 |
+
# def generate_tags(category, context):
|
119 |
+
# """Function to generate tags using Retrieval Augmented Generation
|
120 |
+
# """
|
121 |
+
# try:
|
122 |
+
# API_KEY = st.session_state["OPENAI_API_KEY"]
|
123 |
+
# os.environ['OPENAI_API_KEY'] = API_KEY
|
124 |
+
# except Exception as e:
|
125 |
+
# return st.error("Invalid [OpenAI API key](https://beta.openai.com/account/api-keys) or not found")
|
126 |
+
|
127 |
+
# loader = TextLoader("demoapp/category.txt").load()
|
128 |
+
# text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
129 |
+
# documents = text_splitter.split_documents(loader)
|
130 |
+
# vectorstore = Chroma.from_documents(documents, OpenAIEmbeddings())
|
131 |
+
# retriever = vectorstore.as_retriever()
|
132 |
+
|
133 |
+
# # # Instantiate LLM model
|
134 |
+
# # with get_openai_callback() as cb:
|
135 |
+
|
136 |
+
# template = """You are a trustworthy assistant for question-answering tasks.
|
137 |
+
# Use the following pieces of retrieved context to answer the question.
|
138 |
+
# Question: {question}
|
139 |
+
# Context: {context}
|
140 |
+
# Answer:
|
141 |
+
# """
|
142 |
+
|
143 |
+
# prompt = PromptTemplate.from_template(template)
|
144 |
+
# llm = ChatOpenAI(openai_api_key=API_KEY, temperature=0, model='gpt-4', model_kwargs={'seed': 42})
|
145 |
+
|
146 |
+
# rag_chain = (
|
147 |
+
# {"context": retriever, "question": RunnablePassthrough()}
|
148 |
+
# | prompt
|
149 |
+
# | llm
|
150 |
+
# | StrOutputParser()
|
151 |
+
# )
|
152 |
+
#
|
153 |
+
# query = f"""Output top 3 tags from the category {category} that is relevant to the context {context}"""
|
154 |
+
# response = rag_chain.invoke(query)
|
155 |
+
|
156 |
+
# return response
|
157 |
+
|
158 |
+
|
159 |
+
def generate_response(text, category):
|
160 |
+
"""Function to generate response"""
|
161 |
+
|
162 |
+
API_KEY = st.session_state["OPENAI_API_KEY"]
|
163 |
+
os.environ['OPENAI_API_KEY'] = API_KEY
|
164 |
+
|
165 |
+
loader = TextLoader("demoapp/extracted_mgl.txt").load()
|
166 |
+
text_splitter = CharacterTextSplitter(chunk_size=4000, chunk_overlap=0)
|
167 |
+
documents = text_splitter.split_documents(loader)
|
168 |
+
|
169 |
+
vectorstore = Chroma.from_documents(documents, OpenAIEmbeddings())
|
170 |
+
retriever = vectorstore.as_retriever()
|
171 |
+
|
172 |
+
|
173 |
+
template = """You are a trustworthy assistant for question-answering tasks.
|
174 |
+
Use the following pieces of retrieved context to answer the question.
|
175 |
+
Question: {question}
|
176 |
+
Context: {context}
|
177 |
+
Answer:
|
178 |
+
"""
|
179 |
+
|
180 |
+
prompt = PromptTemplate.from_template(template)
|
181 |
+
llm = ChatOpenAI(openai_api_key=API_KEY, temperature=0, model='gpt-4-1106-preview', model_kwargs={'seed': 42})
|
182 |
+
|
183 |
+
rag_chain = (
|
184 |
+
{"context": retriever, "question": RunnablePassthrough()}
|
185 |
+
| prompt
|
186 |
+
| llm
|
187 |
+
| StrOutputParser()
|
188 |
+
)
|
189 |
+
query = f""" Can you please explain what the following MA bill means to a regular resident without specialized knowledge?
|
190 |
+
Please provide a one paragraph summary in 4 sentences. Please be direct and concise for the busy reader.
|
191 |
+
Note that the bill refers to specific existing sections of the Mass General Laws. Use the information from those sections in your context to construct your summary.
|
192 |
+
Summarize the bill that reads as follows:\n{text}\n\n
|
193 |
+
|
194 |
+
After generating summary, output Category: {category}.
|
195 |
+
Then, output top 3 tags in this specific category from the list of tags {tags_for_bill} that are relevant to this bill. \n"""
|
196 |
+
# Do not output the tags outside from the list. \n
|
197 |
+
# """
|
198 |
+
with get_openai_callback() as cb:
|
199 |
+
response = rag_chain.invoke(query)
|
200 |
+
st.write(cb.total_tokens, cb.prompt_tokens, cb.completion_tokens, cb.total_cost)
|
201 |
+
|
202 |
+
return response
|
203 |
+
|
204 |
+
|
205 |
+
# Function to update or append to CSV
|
206 |
+
def update_csv(bill_num, title, summarized_bill, category, tag, csv_file_path):
|
207 |
+
try:
|
208 |
+
df = pd.read_csv(csv_file_path)
|
209 |
+
except FileNotFoundError:
|
210 |
+
# If the file does not exist, create a new DataFrame
|
211 |
+
df = pd.DataFrame(columns=["Bill Number", "Bill Title", "Summarized Bill", "Category", "Tags"])
|
212 |
+
|
213 |
+
mask = df["Bill Number"] == bill_num
|
214 |
+
if mask.any():
|
215 |
+
df.loc[mask, "Bill Title"] = title
|
216 |
+
df.loc[mask, "Summarized Bill"] = summarized_bill
|
217 |
+
df.loc[mask, "Category"] = category
|
218 |
+
df.loc[mask, "Tags"] = tag
|
219 |
+
else:
|
220 |
+
new_bill = pd.DataFrame([[bill_num, title, summarized_bill, category, tag]], columns=["Bill Number", "Bill Title", "Summarized Bill", "Category", "Tags"])
|
221 |
+
df = pd.concat([df, new_bill], ignore_index=True)
|
222 |
+
|
223 |
+
df.to_csv(csv_file_path, index=False)
|
224 |
+
return df
|
225 |
+
|
226 |
+
csv_file_path = "demoapp/generated_bills.csv"
|
227 |
+
|
228 |
+
|
229 |
+
answer_container = st.container()
|
230 |
+
with answer_container:
|
231 |
+
submit_button = st.button(label='Summarize')
|
232 |
+
col1, col2, col3 = st.columns([1.5, 1.5, 1])
|
233 |
+
|
234 |
+
if submit_button:
|
235 |
+
with st.spinner("Working hard..."):
|
236 |
+
|
237 |
+
category_response = generate_categories(bill_content)
|
238 |
+
response = generate_response(bill_content, category_response)
|
239 |
+
#tag_response = generate_tags(category_response, bill_content)
|
240 |
+
|
241 |
+
with col1:
|
242 |
+
st.subheader(f"Original Bill: #{bill_number}")
|
243 |
+
st.write(bill_title)
|
244 |
+
st.write(bill_content)
|
245 |
+
|
246 |
+
with col2:
|
247 |
+
st.subheader("Generated Text")
|
248 |
+
st.write(response)
|
249 |
+
st.write("###")
|
250 |
+
|
251 |
+
# update_csv(bill_number, bill_title, response, category_response, tag_response, csv_file_path)
|
252 |
+
# st.download_button(
|
253 |
+
# label="Download Text",
|
254 |
+
# data=pd.read_csv("demoapp/generated_bills.csv").to_csv(index=False).encode('utf-8'),
|
255 |
+
# file_name='Bills_Summarization.csv',
|
256 |
+
# mime='text/csv',)
|
257 |
+
|
258 |
+
with col3:
|
259 |
+
st.subheader("Evaluation Metrics")
|
260 |
+
# rouge score addition
|
261 |
+
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
|
262 |
+
rouge_scores = scorer.score(bill_content, response)
|
263 |
+
st.write(f"ROUGE-1 Score: {rouge_scores['rouge1'].fmeasure:.2f}")
|
264 |
+
st.write(f"ROUGE-2 Score: {rouge_scores['rouge2'].fmeasure:.2f}")
|
265 |
+
st.write(f"ROUGE-L Score: {rouge_scores['rougeL'].fmeasure:.2f}")
|
266 |
+
|
267 |
+
# calc cosine similarity
|
268 |
+
vectorizer = TfidfVectorizer()
|
269 |
+
tfidf_matrix = vectorizer.fit_transform([bill_content, response])
|
270 |
+
cosine_sim = cosine_similarity(tfidf_matrix[0], tfidf_matrix[1])
|
271 |
+
st.write(f"Cosine Similarity Score: {cosine_sim[0][0]:.2f}")
|
272 |
+
|
273 |
+
# test hallucination
|
274 |
+
scores = model.predict([
|
275 |
+
[bill_content, response]
|
276 |
+
])
|
277 |
+
score_result = float(scores[0])
|
278 |
+
st.write(f"Factual Consistency Score: {round(score_result, 2)}")
|
279 |
+
|
280 |
+
# st.write("###")
|
281 |
+
# st.subheader("Token Usage")
|
282 |
+
# st.write(f"Response Tokens: {response_tokens + tag_tokens + cate_tokens}")
|
283 |
+
# st.write(f"Prompt Response: {prompt_tokens + tag_tokens + cate_prompt}")
|
284 |
+
# st.write(f"Response Complete:{completion_tokens + tag_completion + cate_completion}")
|
285 |
+
# st.write(f"Response Cost: $ {response_cost + tag_cost + cate_cost}")
|
286 |
+
# st.write(f"Cost: response $ {response_cost + tag_cost + cate_cost}")
|
demoapp/category.txt
ADDED
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
List of Category available: [Environmental, Education, Health Care, Criminal Justice, Taxation, Transportation, Housing, Civil Rights, Labor and Employment, Budget and Appropriations, Public Safety, Technology and Innovation, Immigration, Economic Development, Social Services]
|
2 |
+
|
3 |
+
Category: Environmental
|
4 |
+
|
5 |
+
List of tags in Environmental:
|
6 |
+
|
7 |
+
[Climate Change Mitigation,
|
8 |
+
Renewable Energy Initiatives,
|
9 |
+
Biodiversity Conservation,
|
10 |
+
Water Pollution Control,
|
11 |
+
Sustainable Agriculture Practices,
|
12 |
+
Air Quality Improvement,
|
13 |
+
Waste Reduction Programs,
|
14 |
+
Coastal Erosion Management,
|
15 |
+
Environmental Impact Assessments,
|
16 |
+
Wildlife Habitat Protection]
|
17 |
+
|
18 |
+
Category: Education
|
19 |
+
|
20 |
+
List of tags in Education:
|
21 |
+
|
22 |
+
[Curriculum Development,
|
23 |
+
Digital Learning Resources,
|
24 |
+
Teacher Professional Development,
|
25 |
+
Early Childhood Education,
|
26 |
+
Special Education Services,
|
27 |
+
Literacy Programs,
|
28 |
+
Vocational Training,
|
29 |
+
Education Technology Integration,
|
30 |
+
School Infrastructure Upgrades,
|
31 |
+
Student Mental Health Support]
|
32 |
+
|
33 |
+
Category: Health Care
|
34 |
+
|
35 |
+
List of tags in Health Care:
|
36 |
+
|
37 |
+
[Universal Health Coverage,
|
38 |
+
Healthcare Access for All,
|
39 |
+
Mental Health Services Expansion,
|
40 |
+
Disease Prevention Programs,
|
41 |
+
Elderly Care Services,
|
42 |
+
Healthcare Quality Standards,
|
43 |
+
Health Information Technology,
|
44 |
+
Maternal and Child Health,
|
45 |
+
Public Health Emergency Preparedness,
|
46 |
+
Healthcare Workforce Training]
|
47 |
+
|
48 |
+
Categpry: Criminal Justice
|
49 |
+
|
50 |
+
List of tags in Criminal Justice
|
51 |
+
|
52 |
+
[Police Reforms,
|
53 |
+
Prisoner Rehabilitation,
|
54 |
+
Community Policing Initiatives,
|
55 |
+
Restorative Justice Programs,
|
56 |
+
Criminal Sentencing Reform,
|
57 |
+
Victim Support Services,
|
58 |
+
Legal Aid for the Underprivileged,
|
59 |
+
Juvenile Justice System Overhaul,
|
60 |
+
Hate Crime Prevention Measures,
|
61 |
+
Court System Modernization]
|
62 |
+
|
63 |
+
Category: Taxation
|
64 |
+
|
65 |
+
List of tags in Taxation
|
66 |
+
|
67 |
+
[Progressive Tax Reform,
|
68 |
+
Corporate Taxation Policies,
|
69 |
+
Income Tax Deductions,
|
70 |
+
Property Tax Relief,
|
71 |
+
Sales Tax Revision,
|
72 |
+
Tax Compliance Regulations,
|
73 |
+
Tax Transparency Measures,
|
74 |
+
Wealth Redistribution Initiatives,
|
75 |
+
Small Business Tax Breaks,
|
76 |
+
Tax Fraud Prevention Measures]
|
77 |
+
|
78 |
+
Category: Transportation
|
79 |
+
|
80 |
+
List of tags in Transportation
|
81 |
+
|
82 |
+
[Public Transit Expansion,
|
83 |
+
Road Infrastructure Maintenance,
|
84 |
+
Bike and Pedestrian Path Development,
|
85 |
+
Traffic Congestion Reduction,
|
86 |
+
Electric Vehicle Adoption Incentives,
|
87 |
+
Freight Transportation Efficiency,
|
88 |
+
Aviation Safety Regulations,
|
89 |
+
Railroad Infrastructure Modernization,
|
90 |
+
Intermodal Transportation Integration,
|
91 |
+
Autonomous Vehicle Regulations]
|
92 |
+
|
93 |
+
Category: Housing
|
94 |
+
|
95 |
+
List of tags in Housing
|
96 |
+
|
97 |
+
[Affordable Housing Development,
|
98 |
+
Homelessness Prevention Programs,
|
99 |
+
Rent Control Measures,
|
100 |
+
Fair Housing Enforcement,
|
101 |
+
Housing Discrimination Prevention,
|
102 |
+
Housing Voucher Program Expansion,
|
103 |
+
Sustainable Housing Initiatives,
|
104 |
+
Urban Redevelopment Plans,
|
105 |
+
Eviction Moratoriums,
|
106 |
+
Homeownership Support Programs]
|
107 |
+
|
108 |
+
Category: Civil Rights
|
109 |
+
|
110 |
+
List of tags in Civil Rights
|
111 |
+
|
112 |
+
[Anti-Discrimination Laws,
|
113 |
+
Gender Equality Protections,
|
114 |
+
LGBTQ+ Rights Advocacy,
|
115 |
+
Disability Rights Enforcement,
|
116 |
+
Indigenous Peoples' Rights,
|
117 |
+
Religious Freedom Protection,
|
118 |
+
Language Access Policies,
|
119 |
+
Voting Rights Expansion,
|
120 |
+
Equal Pay Legislation,
|
121 |
+
Minority Rights Safeguards]
|
122 |
+
|
123 |
+
Category: Labor and Employment
|
124 |
+
|
125 |
+
List of tags in Labor and Employment
|
126 |
+
|
127 |
+
[Minimum Wage Increase,
|
128 |
+
Occupational Safety Regulations,
|
129 |
+
Labor Union Protections,
|
130 |
+
Workplace Harassment Prevention,
|
131 |
+
Job Training and Apprenticeships,
|
132 |
+
Workforce Diversity Initiatives,
|
133 |
+
Employee Benefits Expansion,
|
134 |
+
Fair Working Hours Regulations,
|
135 |
+
Unemployment Benefits Enhancement,
|
136 |
+
Remote Work Policies]
|
137 |
+
|
138 |
+
Category: Budget and Appropriations
|
139 |
+
|
140 |
+
List of tags in Budget and Appropriations
|
141 |
+
|
142 |
+
[Government Spending Oversight,
|
143 |
+
Emergency Fund Allocation,
|
144 |
+
Public Debt Management,
|
145 |
+
Fiscal Responsibility Audits,
|
146 |
+
Public Infrastructure Investment,
|
147 |
+
Social Welfare Program Funding,
|
148 |
+
Pension Plan Reform,
|
149 |
+
Local Government Grant Programs,
|
150 |
+
Financial Aid for Disadvantaged Communities,
|
151 |
+
Tax Revenue Allocation]
|
152 |
+
|
153 |
+
Category: Public Safety
|
154 |
+
|
155 |
+
List of tags in Public Safety
|
156 |
+
|
157 |
+
[Emergency Response Planning,
|
158 |
+
Disaster Preparedness Training,
|
159 |
+
Cybersecurity Protocols,
|
160 |
+
Domestic Violence Prevention,
|
161 |
+
Fire Safety Regulations,
|
162 |
+
Gun Control Measures,
|
163 |
+
Community Health and Safety Programs,
|
164 |
+
Public Health Crisis Management,
|
165 |
+
Hate Crime Reporting Systems,
|
166 |
+
Crime Prevention Initiatives]
|
167 |
+
|
168 |
+
Category: Technology and Innovation
|
169 |
+
|
170 |
+
List of tags in Technology and Innovation
|
171 |
+
|
172 |
+
[Digital Privacy Laws,
|
173 |
+
Data Security Measures,
|
174 |
+
Innovation Investment Policies,
|
175 |
+
Broadband Infrastructure Expansion,
|
176 |
+
E-Government Service Enhancements,
|
177 |
+
Technology Education in Schools,
|
178 |
+
Artificial Intelligence Regulations,
|
179 |
+
Privacy Protection for Biometric Data,
|
180 |
+
Blockchain Integration Strategies]
|
181 |
+
Open Data Initiatives
|
182 |
+
|
183 |
+
Category: Immigration
|
184 |
+
|
185 |
+
List of tags in Immigration
|
186 |
+
|
187 |
+
[Immigration Policy Reform,
|
188 |
+
Refugee Resettlement Programs,
|
189 |
+
Asylum Seeker Protections,
|
190 |
+
Migrant Worker Rights,
|
191 |
+
Language Access Services,
|
192 |
+
Family Reunification Initiatives,
|
193 |
+
Pathways to Citizenship,
|
194 |
+
Humanitarian Aid for Migrants,
|
195 |
+
Border Security Measures,
|
196 |
+
Anti-Trafficking Efforts]
|
197 |
+
|
198 |
+
Category: Economic Development
|
199 |
+
|
200 |
+
List of tags in Economic Development
|
201 |
+
|
202 |
+
[Small Business Support Programs,
|
203 |
+
Export Promotion Policies,
|
204 |
+
Rural Development Initiatives,
|
205 |
+
Entrepreneurship Training,
|
206 |
+
Trade Agreement Negotiations,
|
207 |
+
Tourism Industry Growth,
|
208 |
+
Regional Economic Integration,
|
209 |
+
Financial Inclusion Programs,
|
210 |
+
Economic Diversification Strategies,
|
211 |
+
Infrastructure Investment Plans]
|
212 |
+
|
213 |
+
Category: Social Services
|
214 |
+
|
215 |
+
List of tags in Social Services
|
216 |
+
|
217 |
+
[Child Welfare Services,
|
218 |
+
Domestic Violence Support,
|
219 |
+
Elderly Care Programs,
|
220 |
+
Foster Care System Reforms,
|
221 |
+
Disability Assistance Programs,
|
222 |
+
Community Support Services,
|
223 |
+
Youth Mentorship Programs,
|
224 |
+
Substance Abuse Rehabilitation,
|
225 |
+
Home Care for the Disabled,
|
226 |
+
Affordable Childcare Services]
|
demoapp/extracted_mgl.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
demoapp/generated_bills.csv
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Bill Number,Bill Title,Summarized Bill,Category,Tags
|
2 |
+
H20, An Act clarifying and normalizing non-public school service purchases,"Summary: An Act clarifying and normalizing non-public school service purchases allows members of a contributory retirement system who were previously employed as teachers in special education programs for school-aged children in non-public schools in Massachusetts to establish such service as creditable service by making a deposit into the annuity savings fund of the system. The bill specifies the conditions and terms for making such deposits and the maximum credit for service in non-public schools. It also defines ""non-public school"" and excludes activities in a residence or afterschool program from the definition.",Education,"1. Curriculum Development
|
3 |
+
2. Teacher Professional Development
|
4 |
+
3. Special Education Services"
|
5 |
+
H1," An Act making appropriations for the Fiscal Year 2024 for the maintenance of the departments, boards, commissions, institutions, and certain activities of the Commonwealth, for interest, sinking fund, and serial bond requirements, and for certain permanent improvements","Summary: An Act making appropriations for the Fiscal Year 2024 for the maintenance of the departments, boards, commissions, institutions, and certain activities of the Commonwealth, for interest, sinking fund, and serial bond requirements, and for certain permanent improvements. This bill outlines the budget allocations for various departments, boards, commissions, and institutions of the Commonwealth for the fiscal year 2024. It also includes provisions for interest, sinking fund, and serial bond requirements, as well as funding for certain permanent improvements. The bill may also include any amendments made during the legislative process.",The bill cannot be classified as it is labeled as 'nan' which typically means 'not a number' or 'not available'. More information is needed to classify the bill.,"The question does not provide a specific category to select tags from. However, based on the context provided, here are the top three tags from a few categories:
|
6 |
+
|
7 |
+
1. Budget and Appropriations: Government Spending Oversight, Emergency Fund Allocation, Public Debt Management
|
8 |
+
2. Public Safety: Emergency Response Planning, Disaster Preparedness Training, Cybersecurity Protocols
|
9 |
+
3. Environmental: Climate Change Mitigation, Renewable Energy Initiatives, Biodiversity Conservation
|
10 |
+
4. Transportation: Public Transit Expansion, Road Infrastructure Maintenance, Bike and Pedestrian Path Development
|
11 |
+
5. Technology and Innovation: Digital Privacy Laws, Data Security Measures, Innovation Investment Policies
|
12 |
+
|
13 |
+
Please specify a category for a more precise answer."
|
14 |
+
H10, An Act relative to the recovery of overearnings,"Summary: An Act relative to the recovery of overearnings
|
15 |
+
|
16 |
+
This bill seeks to amend paragraph (c) of Section 91 of chapter 32 of the general laws. The proposed amendment allows the retirement board of which the member is a retiree to recover an amount equal to the overearnings if the excess is not recovered by the appropriate treasurer or other person responsible for the payment of the compensation. However, the amount of the recovery cannot exceed the amount of the retirement allowance paid in the year in which the overearnings occurred.",Budget and Appropriations,"1. Government Spending Oversight
|
17 |
+
2. Public Debt Management
|
18 |
+
3. Pension Plan Reform"
|
19 |
+
H1000, An Act providing living organ donor protections,"Summary: An Act providing living organ donor protections
|
20 |
+
|
21 |
+
This bill aims to protect living organ donors from discrimination by insurance companies. It requires the commissioner of insurance to create rules and regulations to enforce the protection of living organ donors. It also mandates that the department of health make materials related to live organ donation available to the public. Additionally, the bill prohibits insurers from declining or limiting coverage, precluding donation as a condition of coverage, or otherwise discriminating against living organ donors in policies for disability, life insurance, annuities, and long-term care insurance. Violations of these provisions are considered unfair practices under the law.",Health Care,"1. Universal Health Coverage
|
22 |
+
2. Healthcare Access for All
|
23 |
+
3. Health Information Technology"
|
demoapp/requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain==0.0.335
|
2 |
+
openai==1.3.4
|
3 |
+
pandas==2.1.3
|
4 |
+
streamlit==1.28.2
|
5 |
+
scikit-learn==1.3.2
|
6 |
+
rouge-score==0.1.2
|
7 |
+
chromadb==0.4.18
|
8 |
+
tiktoken==0.5.1
|
9 |
+
sentence-transformers==2.2.2
|
10 |
+
pysqlite3-binary==0.5.2
|
demoapp/sidebar.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def set_openai_api_key(api_key: str):
|
4 |
+
try:
|
5 |
+
st.session_state["OPENAI_API_KEY"] = api_key
|
6 |
+
except Exception as e:
|
7 |
+
return("error")
|
8 |
+
|
9 |
+
|
10 |
+
def sbar():
|
11 |
+
with st.sidebar:
|
12 |
+
st.markdown("## How to use\n"
|
13 |
+
"1. Enter your [OpenAI API key](https://platform.openai.com/account/api-keys) below🔑\n"
|
14 |
+
"2. Press enter")
|
15 |
+
API_KEY = st.text_input("OpenAI API Key",
|
16 |
+
placeholder="Paste your OpenAI API key here (sk-...)",
|
17 |
+
type="password")
|
18 |
+
|
19 |
+
st.markdown("---")
|
20 |
+
st.markdown("# About\n")
|
21 |
+
st.write("input 0.0010 per 1000 tokens, output 0.0020 per 1000 tokens")
|
22 |
+
st.markdown("---")
|
23 |
+
st.markdown("Privacy")
|
24 |
+
st.markdown(
|
25 |
+
"Your API key will not saved at all."
|
26 |
+
)
|
27 |
+
st.markdown("This tool is a work in progress")
|
28 |
+
|
29 |
+
if API_KEY:
|
30 |
+
set_openai_api_key(API_KEY)
|
demoapp/tagging.py
ADDED
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
category_for_bill = """
|
2 |
+
[Environmental, Education, Health Care, Criminal Justice, Taxation, Transportation,
|
3 |
+
Housing, Civil Rights, Labor and Employment, Budget and Appropriations, Public Safety, Technology and Innovation,
|
4 |
+
Immigration, Economic Development, Social Services]
|
5 |
+
"""
|
6 |
+
|
7 |
+
tags_for_bill = """
|
8 |
+
|
9 |
+
{"Environmental": [Climate Change Mitigation,
|
10 |
+
Renewable Energy Initiatives,
|
11 |
+
Biodiversity Conservation,
|
12 |
+
Water Pollution Control,
|
13 |
+
Sustainable Agriculture Practices,
|
14 |
+
Air Quality Improvement,
|
15 |
+
Waste Reduction Programs,
|
16 |
+
Coastal Erosion Management,
|
17 |
+
Environmental Impact Assessments,
|
18 |
+
Wildlife Habitat Protection],
|
19 |
+
|
20 |
+
"Education": [Curriculum Development,
|
21 |
+
Digital Learning Resources,
|
22 |
+
Teacher Professional Development,
|
23 |
+
Early Childhood Education,
|
24 |
+
Special Education Services,
|
25 |
+
Literacy Programs,
|
26 |
+
Vocational Training,
|
27 |
+
Education Technology Integration,
|
28 |
+
School Infrastructure Upgrades,
|
29 |
+
Student Mental Health Support],
|
30 |
+
|
31 |
+
"Health Care": [Universal Health Coverage,
|
32 |
+
Healthcare Access for All,
|
33 |
+
Mental Health Services Expansion,
|
34 |
+
Disease Prevention Programs,
|
35 |
+
Elderly Care Services,
|
36 |
+
Healthcare Quality Standards,
|
37 |
+
Health Information Technology,
|
38 |
+
Maternal and Child Health,
|
39 |
+
Public Health Emergency Preparedness,
|
40 |
+
Healthcare Workforce Training],
|
41 |
+
|
42 |
+
"Criminal Justice": [Police Reforms,
|
43 |
+
Prisoner Rehabilitation,
|
44 |
+
Community Policing Initiatives,
|
45 |
+
Restorative Justice Programs,
|
46 |
+
Criminal Sentencing Reform,
|
47 |
+
Victim Support Services,
|
48 |
+
Legal Aid for the Underprivileged,
|
49 |
+
Juvenile Justice System Overhaul,
|
50 |
+
Hate Crime Prevention Measures,
|
51 |
+
Court System Modernization],
|
52 |
+
|
53 |
+
"Taxation": [Progressive Tax Reform,
|
54 |
+
Corporate Taxation Policies,
|
55 |
+
Income Tax Deductions,
|
56 |
+
Property Tax Relief,
|
57 |
+
Sales Tax Revision,
|
58 |
+
Tax Compliance Regulations,
|
59 |
+
Tax Transparency Measures,
|
60 |
+
Wealth Redistribution Initiatives,
|
61 |
+
Small Business Tax Breaks,
|
62 |
+
Tax Fraud Prevention Measures],
|
63 |
+
|
64 |
+
"Transportation": [Public Transit Expansion,
|
65 |
+
Road Infrastructure Maintenance,
|
66 |
+
Bike and Pedestrian Path Development,
|
67 |
+
Traffic Congestion Reduction,
|
68 |
+
Electric Vehicle Adoption Incentives,
|
69 |
+
Freight Transportation Efficiency,
|
70 |
+
Aviation Safety Regulations,
|
71 |
+
Railroad Infrastructure Modernization,
|
72 |
+
Intermodal Transportation Integration,
|
73 |
+
Autonomous Vehicle Regulations],
|
74 |
+
|
75 |
+
"Housing": [Affordable Housing Development,
|
76 |
+
Homelessness Prevention Programs,
|
77 |
+
Rent Control Measures,
|
78 |
+
Fair Housing Enforcement,
|
79 |
+
Housing Discrimination Prevention,
|
80 |
+
Housing Voucher Program Expansion,
|
81 |
+
Sustainable Housing Initiatives,
|
82 |
+
Urban Redevelopment Plans,
|
83 |
+
Eviction Moratoriums,
|
84 |
+
Homeownership Support Programs],
|
85 |
+
|
86 |
+
"Civil Rights": [Anti-Discrimination Laws,
|
87 |
+
Gender Equality Protections,
|
88 |
+
LGBTQ+ Rights Advocacy,
|
89 |
+
Disability Rights Enforcement,
|
90 |
+
Indigenous Peoples' Rights,
|
91 |
+
Religious Freedom Protection,
|
92 |
+
Language Access Policies,
|
93 |
+
Voting Rights Expansion,
|
94 |
+
Equal Pay Legislation,
|
95 |
+
Minority Rights Safeguards],
|
96 |
+
|
97 |
+
"Labor and Employment": [Minimum Wage Increase,
|
98 |
+
Occupational Safety Regulations,
|
99 |
+
Labor Union Protections,
|
100 |
+
Workplace Harassment Prevention,
|
101 |
+
Job Training and Apprenticeships,
|
102 |
+
Workforce Diversity Initiatives,
|
103 |
+
Employee Benefits Expansion,
|
104 |
+
Fair Working Hours Regulations,
|
105 |
+
Unemployment Benefits Enhancement,
|
106 |
+
Remote Work Policies],
|
107 |
+
|
108 |
+
"Budget and Appropriations": [Government Spending Oversight,
|
109 |
+
Emergency Fund Allocation,
|
110 |
+
Public Debt Management,
|
111 |
+
Fiscal Responsibility Audits,
|
112 |
+
Public Infrastructure Investment,
|
113 |
+
Social Welfare Program Funding,
|
114 |
+
Pension Plan Reform,
|
115 |
+
Local Government Grant Programs,
|
116 |
+
Financial Aid for Disadvantaged Communities,
|
117 |
+
Tax Revenue Allocation]
|
118 |
+
|
119 |
+
"Public Safety": [Emergency Response Planning,
|
120 |
+
Disaster Preparedness Training,
|
121 |
+
Cybersecurity Protocols,
|
122 |
+
Domestic Violence Prevention,
|
123 |
+
Fire Safety Regulations,
|
124 |
+
Gun Control Measures,
|
125 |
+
Community Health and Safety Programs,
|
126 |
+
Public Health Crisis Management,
|
127 |
+
Hate Crime Reporting Systems,
|
128 |
+
Crime Prevention Initiatives],
|
129 |
+
|
130 |
+
"Technology and Innovation": [Digital Privacy Laws,
|
131 |
+
Data Security Measures,
|
132 |
+
Innovation Investment Policies,
|
133 |
+
Broadband Infrastructure Expansion,
|
134 |
+
E-Government Service Enhancements,
|
135 |
+
Technology Education in Schools,
|
136 |
+
Artificial Intelligence Regulations,
|
137 |
+
Privacy Protection for Biometric Data,
|
138 |
+
Blockchain Integration Strategies]
|
139 |
+
Open Data Initiatives
|
140 |
+
|
141 |
+
"Immigration": [Immigration Policy Reform,
|
142 |
+
Refugee Resettlement Programs,
|
143 |
+
Asylum Seeker Protections,
|
144 |
+
Migrant Worker Rights,
|
145 |
+
Language Access Services,
|
146 |
+
Family Reunification Initiatives,
|
147 |
+
Pathways to Citizenship,
|
148 |
+
Humanitarian Aid for Migrants,
|
149 |
+
Border Security Measures,
|
150 |
+
Anti-Trafficking Efforts],
|
151 |
+
|
152 |
+
"Economic Development": [Small Business Support Programs,
|
153 |
+
Export Promotion Policies,
|
154 |
+
Rural Development Initiatives,
|
155 |
+
Entrepreneurship Training,
|
156 |
+
Trade Agreement Negotiations,
|
157 |
+
Tourism Industry Growth,
|
158 |
+
Regional Economic Integration,
|
159 |
+
Financial Inclusion Programs,
|
160 |
+
Economic Diversification Strategies,
|
161 |
+
Infrastructure Investment Plans],
|
162 |
+
|
163 |
+
"Social Services": [Child Welfare Services,
|
164 |
+
Domestic Violence Support,
|
165 |
+
Elderly Care Programs,
|
166 |
+
Foster Care System Reforms,
|
167 |
+
Disability Assistance Programs,
|
168 |
+
Community Support Services,
|
169 |
+
Youth Mentorship Programs,
|
170 |
+
Substance Abuse Rehabilitation,
|
171 |
+
Home Care for the Disabled,
|
172 |
+
Affordable Childcare Services]
|
173 |
+
"""
|
174 |
+
|
175 |
+
tagging = """
|
176 |
+
[Climate Change Mitigation,
|
177 |
+
Renewable Energy Initiatives,
|
178 |
+
Biodiversity Conservation,
|
179 |
+
Water Pollution Control,
|
180 |
+
Sustainable Agriculture Practices,
|
181 |
+
Air Quality Improvement,
|
182 |
+
Waste Reduction Programs,
|
183 |
+
Coastal Erosion Management,
|
184 |
+
Environmental Impact Assessments,
|
185 |
+
Wildlife Habitat Protection,
|
186 |
+
Curriculum Development,
|
187 |
+
Digital Learning Resources,
|
188 |
+
Teacher Professional Development,
|
189 |
+
Early Childhood Education,
|
190 |
+
Special Education Services,
|
191 |
+
Literacy Programs,
|
192 |
+
Vocational Training,
|
193 |
+
Education Technology Integration,
|
194 |
+
School Infrastructure Upgrades,
|
195 |
+
Student Mental Health Support,
|
196 |
+
Universal Health Coverage,
|
197 |
+
Healthcare Access for All,
|
198 |
+
Mental Health Services Expansion,
|
199 |
+
Disease Prevention Programs,
|
200 |
+
Elderly Care Services,
|
201 |
+
Healthcare Quality Standards,
|
202 |
+
Health Information Technology,
|
203 |
+
Maternal and Child Health,
|
204 |
+
Public Health Emergency Preparedness,
|
205 |
+
Healthcare Workforce Training,
|
206 |
+
Police Reforms,
|
207 |
+
Prisoner Rehabilitation,
|
208 |
+
Community Policing Initiatives,
|
209 |
+
Restorative Justice Programs,
|
210 |
+
Criminal Sentencing Reform,
|
211 |
+
Victim Support Services,
|
212 |
+
Legal Aid for the Underprivileged,
|
213 |
+
Juvenile Justice System Overhaul,
|
214 |
+
Hate Crime Prevention Measures,
|
215 |
+
Court System Modernization,
|
216 |
+
Progressive Tax Reform,
|
217 |
+
Corporate Taxation Policies,
|
218 |
+
Income Tax Deductions,
|
219 |
+
Property Tax Relief,
|
220 |
+
Sales Tax Revision,
|
221 |
+
Tax Compliance Regulations,
|
222 |
+
Tax Transparency Measures,
|
223 |
+
Wealth Redistribution Initiatives,
|
224 |
+
Small Business Tax Breaks,
|
225 |
+
Tax Fraud Prevention Measures,
|
226 |
+
Public Transit Expansion,
|
227 |
+
Road Infrastructure Maintenance,
|
228 |
+
Bike and Pedestrian Path Development,
|
229 |
+
Traffic Congestion Reduction,
|
230 |
+
Electric Vehicle Adoption Incentives,
|
231 |
+
Freight Transportation Efficiency,
|
232 |
+
Aviation Safety Regulations,
|
233 |
+
Railroad Infrastructure Modernization,
|
234 |
+
Intermodal Transportation Integration,
|
235 |
+
Autonomous Vehicle Regulations,
|
236 |
+
Affordable Housing Development,
|
237 |
+
Homelessness Prevention Programs,
|
238 |
+
Rent Control Measures,
|
239 |
+
Fair Housing Enforcement,
|
240 |
+
Housing Discrimination Prevention,
|
241 |
+
Housing Voucher Program Expansion,
|
242 |
+
Sustainable Housing Initiatives,
|
243 |
+
Urban Redevelopment Plans,
|
244 |
+
Eviction Moratoriums,
|
245 |
+
Homeownership Support Programs,
|
246 |
+
Anti-Discrimination Laws,
|
247 |
+
Gender Equality Protections,
|
248 |
+
LGBTQ+ Rights Advocacy,
|
249 |
+
Disability Rights Enforcement,
|
250 |
+
Indigenous Peoples' Rights,
|
251 |
+
Religious Freedom Protection,
|
252 |
+
Language Access Policies,
|
253 |
+
Voting Rights Expansion,
|
254 |
+
Equal Pay Legislation,
|
255 |
+
Minority Rights Safeguards,
|
256 |
+
Minimum Wage Increase,
|
257 |
+
Occupational Safety Regulations,
|
258 |
+
Labor Union Protections,
|
259 |
+
Workplace Harassment Prevention,
|
260 |
+
Job Training and Apprenticeships,
|
261 |
+
Workforce Diversity Initiatives,
|
262 |
+
Employee Benefits Expansion,
|
263 |
+
Fair Working Hours Regulations,
|
264 |
+
Unemployment Benefits Enhancement,
|
265 |
+
Remote Work Policies,
|
266 |
+
Government Spending Oversight,
|
267 |
+
Emergency Fund Allocation,
|
268 |
+
Public Debt Management,
|
269 |
+
Fiscal Responsibility Audits,
|
270 |
+
Public Infrastructure Investment,
|
271 |
+
Social Welfare Program Funding,
|
272 |
+
Pension Plan Reform,
|
273 |
+
Local Government Grant Programs,
|
274 |
+
Financial Aid for Disadvantaged Communities,
|
275 |
+
Tax Revenue Allocation,
|
276 |
+
Emergency Response Planning,
|
277 |
+
Disaster Preparedness Training,
|
278 |
+
Cybersecurity Protocols,
|
279 |
+
Domestic Violence Prevention,
|
280 |
+
Fire Safety Regulations,
|
281 |
+
Gun Control Measures,
|
282 |
+
Community Health and Safety Programs,
|
283 |
+
Public Health Crisis Management,
|
284 |
+
Hate Crime Reporting Systems,
|
285 |
+
Crime Prevention Initiatives,
|
286 |
+
Digital Privacy Laws,
|
287 |
+
Data Security Measures,
|
288 |
+
Innovation Investment Policies,
|
289 |
+
Broadband Infrastructure Expansion,
|
290 |
+
E-Government Service Enhancements,
|
291 |
+
Technology Education in Schools,
|
292 |
+
Artificial Intelligence Regulations,
|
293 |
+
Privacy Protection for Biometric Data,
|
294 |
+
Blockchain Integration Strategies,
|
295 |
+
Open Data Initiatives,
|
296 |
+
Immigration Policy Reform,
|
297 |
+
Refugee Resettlement Programs,
|
298 |
+
Asylum Seeker Protections,
|
299 |
+
Migrant Worker Rights,
|
300 |
+
Language Access Services,
|
301 |
+
Family Reunification Initiatives,
|
302 |
+
Pathways to Citizenship,
|
303 |
+
Humanitarian Aid for Migrants,
|
304 |
+
Border Security Measures,
|
305 |
+
Anti-Trafficking Efforts,
|
306 |
+
Small Business Support Programs,
|
307 |
+
Export Promotion Policies,
|
308 |
+
Rural Development Initiatives,
|
309 |
+
Entrepreneurship Training,
|
310 |
+
Trade Agreement Negotiations,
|
311 |
+
Tourism Industry Growth,
|
312 |
+
Regional Economic Integration,
|
313 |
+
Financial Inclusion Programs,
|
314 |
+
Economic Diversification Strategies,
|
315 |
+
Infrastructure Investment Plans,
|
316 |
+
Child Welfare Services,
|
317 |
+
Domestic Violence Support,
|
318 |
+
Elderly Care Programs,
|
319 |
+
Foster Care System Reforms,
|
320 |
+
Disability Assistance Programs,
|
321 |
+
Community Support Services,
|
322 |
+
Youth Mentorship Programs,
|
323 |
+
Substance Abuse Rehabilitation,
|
324 |
+
Home Care for the Disabled,
|
325 |
+
Affordable Childcare Services,
|
326 |
+
]
|
327 |
+
"""
|
328 |
+
|
329 |
+
|
330 |
+
|