Giter VIP home page Giter VIP logo

Comments (2)

cmdoret avatar cmdoret commented on June 12, 2024 2

Skeleton example:

Corpus downloader:

import json
import requests

resp = requests.get("https://raw.githubusercontent.com/spdx/license-list-data/main/json/licenses.json")
all_licenses = json.loads(resp.text)

for i, lic in all_licenses['licenses']:
    r = requests.get(lic["detailsUrl"])
    lic["text"] = json.loads(r.text)["licenseText"]

with open('licenses.json', 'w') as fp:
    json.dump(all_licenses, fp)

Vectorizer:

import json
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer

with open('licenses.json', 'r') as fp:
    all_licenses = json.load(fp)

corpus = [lic['text'] for lic in all_licenses['licenses']]
vectorizer = TfidfVectorizer()
tfidf = vectorizer.fit_transform(corpus)
pickle.dump(vectorizer, open('vectorizer.pickle', 'wb'))
pickle.dump(tfidf, open('tfidf.pickle', 'wb'))

Note: since downloading + building the vectorizer is a one-time job (not performed by users), speed is not crucial. We may want to implement the vectorizer ourselves to avoid depending on sklearn + storing unneeded metadata in the vectorizer.

Resources:

from gimie.

cmdoret avatar cmdoret commented on June 12, 2024 1

Had some fun implementing a pure-python json-serializable TfidVectorizer. It has a subset of the parameters supported by sklearn and gives identical results. It is slower, but inference for a license takes ~0.2 sec.

https://gist.github.com/cmdoret/4ea255e8adb398938f9d5114a4dfd373

from gimie.

Related Issues (20)

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.