Code Monkey home page Code Monkey logo

wri-dssg-omdena / policy-data-analyzer Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 10.0 231.57 MB

Building a model to recognize incentives for landscape restoration in environmental policies from Latin America, the US and India. Bringing NLP to the world of policy analysis through an extensible framework that includes scraping, preprocessing, active learning and text analysis pipelines.

License: Other

Makefile 0.01% Jupyter Notebook 91.93% Python 1.22% R 0.08% CSS 5.10% JavaScript 0.02% HTML 1.61% Shell 0.01% Dockerfile 0.02%
nlp sbert sentence-transformers huggingface machine-learning text-classification document-classification scraping policy environmental

policy-data-analyzer's People

Contributors

bcjg23 avatar danncalle avatar dfhssilva avatar galiusha avatar mattesweeney avatar rongfang323 avatar rsmath avatar thefirebanks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

policy-data-analyzer's Issues

Code refactoring for the data augmentation notebook.

One important estep in the project pipeline is to find a batch of prelabeled sentences that can be easily curated manually to be later used for model fine-tuning.
In a first step this was done in a notebook where different strategies where evaluated in different experimental setups.
Now this code should be cleaned and refactored to be integrated in the final pipeline.

Identify best set of keywords and search terms to find relevant documents from Ecolex

After the text has been extracted from the policy PDFs:

  1. Find word embeddings suitable for Spanish documents, or any type of Spanish language model
  2. Use keyword analysis/topic modeling to gather insights from the text and improve further searches
  3. If possible, come up with a "similarity" or "distance" metric among relevant documents for easier filtering from non-relevant

SBERT for classification

Find a way of using SBERT for label prediction without using cosine similarity - i.e Find another mapping function from sentence embedding to label

data loading refactoring and new functions

This is an issue to improve the data loading tools. You can list your changes here:

  • Rename the function to load json from "load_file" to "load_json" in the src/utils.py
  • Add a funtion to list file names from a directory

Explore query strategies with sBERT

We have a initial setup of sBERT to be able to get sentence embeddings and then find the cosine similarity between two sentences.
This allows for using this setup as a search engine to look for sentences which are similar to a certain query.
In this issue we want to analyse the output of the search as we use different query approaches.
There is a more sophisticated approach in https://towardsdatascience.com/building-a-search-engine-with-bert-and-tensorflow-c6fdc0186c8a that we will also explore to see if the performance improves. We will set a new branch Antyukhov-search-engine

Create a general evaluator for the models

Script that:

  • Takes in as input the results from a given model run (as a JSON file containing sentences and their labels) and a dataset of labeled sentences
  • Compares the differences between the model outputs and the ground truth
  • Has different metrics (cosine similarity, accuracy, precision-recall curve, etc.)

Improve preprocessing component

The current method that we are using to split sentences yields a great amount of wrongly splitt sentences.
We need to improve it so as to have a good final version when we want to use the fine-tunned transformers.

Edit README

Make changes to the README so that it contains updated information about the architecture, results and description of the project. The end goal is to spread the link to this repo as much as possible, and we need to have a good and presentable description of the project.

Automate hyperparameter optimization

  • Look for information on automatic hyperparameter tuning optimization and its viability for our project
  • Define hyperparameters to be optimized for
  • Test new methods like population-based optimization or bayesian optimization

Bayesian Optimization explained

Population Based Optimization

Huggingface + Ray + W&B implementation of hyperparameter tuning

Extract text from Cristina's documents

  1. Read pdf files directly from OneDrive or from zip file
  2. Use OCR if needed for extracting text from image pdf files
  3. Optional: Structure data into single file (or database) for future reading

Spiders for US legislation

  • Rethink the database schema
  • Improve the is_enforced field update
  • Extend the is_enforced field to all spiders
  • Include the SHA1 code as the file name
  • Check the publication date field so that we have a uniformized format whether date-time or txt
  • Centralize the loading of the dictionaries in a specific folder
  • Centralize the output csv files into a specific folder.
  • Create spider for the US federal policies
  • Create spider for the US state official bulletins (Selected states)
  • Update dictionaries in English
  • Implement the SQL database again
  • Move date transformations to a function in init.py

Weights & Biases experiments

Setup for Weights & Biases for our notebook and further experiments

We can use wandb for hyperparameter tuning and most importantly keeping track of experiments. With W&B free hosted service we can set this up efficiently.

Since the team version of wandb is paid (30 day free trial is there however), we will use the following project

https://wandb.ai/ramanshsharma/WRI

Please find the API key to write to the public project in Slack.

Goals

  • Create a shared project on weights & biases for the team to work on.
  • Set up training and validation accuracy/loss, weighted/macro F1 score plotting
  • Set up automatic hyperparameter tuning

Helpful links

  1. Intro to Weights & Biases
  2. Official examples
  3. Organizing Hyperparameter Sweeps in PyTorch with W&B

Fix training loops and sentence transformer

  • Evaluation code should be refactored to only take care of calculating results, and storing of results should be done in a different area
  • Evaluation should be done on validation set, not test set
  • Add method to evaluate on test set

Refactor preprocessing script

We can refactor src/preprocessing.py and make it slightly more readable/time efficient, as well as easy to add more transformations to the text

Setup binary classifier

Fine-tune BERT with a multilingual transformer to discriminate is_incentive from is_not_incentive

Set up AWS S3 general pipelines

According to the process diagrams, for each language, there will be many different databases, in the main bucket wri-nlp-policy.

GOAL: For each of the folders/content inside, we need to create functions that allow for easy access and manipulation.

An example structure for the english documents would be:

  • /english_documents/raw_pdf/: Original/raw documents
  • /english_documents/text_files/: Text file version of the documents
    • /english_documents/text_files/new/: New documents ready to be processed (read)
    • /english_documents/text_files/processed/: Processed documents that have already gone through sentence extraction (write)
  • /english_documents/sentences/: JSON file containing sentences per documents (read AND write)
  • /english_documents/assisted_labeling/: Excel/CSV files for the assisted labeling part (read AND write)
  • /english_documents/metadata/: CSV files containing metadata for each country (file names, title of document, etc.) (write)
  • /english_documents/abbreviations/: Text files containing common abbreviations for each language (read)
  • Extra separate files:
    • /english_documents/english_queries.xlsx: Queries (Excel) (read)

There are more databases to add, such as the one for actual embeddings (if needed) and the highlights per each document. Since we haven't created them yet, these are not necessary to create links to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.