Git Product home page Git Product logo

bert_vector_clustering's Introduction

bert_vector_clustering

Clustering learned BERT vectors for downstream tasks like unsupervised NER, unsupervised sentence embeddings etc.

Unsupervised training of BERT yields a model and context insenstive word vectors. These word vectors are stored in pytorch_model.bin. This repository has simple utilities to extract those vectors, cluster them, etc.

Medium post that uses this repository tools to cluster BERT's context insensitive word vectors for unsupervised NER

Steps to cluster

Step 1a: Fetch a model and its vocab file using fetch_model.sh

./fetch_model.sh

This will download bert_large_cased and its vocab for testing.

** Refer to huggingface model repositories for other model URLs. **

Step 1b: Extract vectors from the model

python examine_model.py 2 > bert_vectors.txt	

Step 1c: Execute run.sh and then choose option 1 to create cluster file debug_pivots.txt

Step 1d: Run

./extract_labels.sh

to combine user defined labels in map_labels.txt and debug_pivots.txt.

Note these user labels are only applicable to bert_large_cased model clustering. One would have to create a new map_labels.txt file from debug_pivots.txt for another model

Additionally

./run.sh

has options to look at cumulative distribution of a model's words, find pivot among a set of terms, entity labeling, etc.

Sample Outputs

Output of clustering using bert_large_cased are in results directory

cum_dist.txt - output of run.sh with option 1

debug_pivots.txt - output of run.sh with option 2

labels.txt and stats_dict.txt - output of running extract_labels.sh

Steps to run this as a service for downstream unsupervised NER

./run_dist_v2_server.sh

To test this service

  • wget -O out http://127.0.0.1:8043/"cat dog cow horse"

  • cat out

    BIO-SPECIES BIO-SPECIES BIO-SPECIES BIO BIO BIO BIO BIO BIO BIO

    The descriptors "cat dog cow horse" are typically the predictions for a masked word in a sentence. The results are all BIO-SPECIES or BIO capturing the entity type of the masked word. Refer to the medium post link above for more details

License

This repository is covered by MIT license.

bert_vector_clustering's People

Contributors

ajitrajasekharan avatar

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.