Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Parameterize classifier model #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Model downloads
models/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -139,4 +142,4 @@ cython_debug/

#others
nohup.out
.DS_Store
.DS_Store
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[metadata]
[project]
name = 'zeroshot_topics'
version = '0.0.1'
description = 'Topic Inference with Zeroshot models'
author = 'AnjanaRita'
author_email = '[email protected]'
license = 'MIT/Apache-2.0'
license = 'MIT'
url = 'https://github.com/AnjanaRita/zeroshot_topics'

[requires]
python_version = ['2.7', '3.5', '3.6', 'pypy', 'pypy3']

[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'hatchling.build'
requires = ['hatchling', 'setuptools', 'wheel']

[tool.hatch.commands]
prerelease = 'hatch build'
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
attrs==20.3.0
nltk==3.6.5
keybert==0.5.0
transformers==4.11.0
attrs==22.1.0
nltk==3.7
keybert==0.7.0
transformers==4.25.1
8 changes: 7 additions & 1 deletion zeroshot_topics/zeroshot_tm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from nltk.corpus import wordnet as wn

classifier = load_zeroshot_model()
classifier = None
# load_zeroshot_model()


@attr.s
Expand All @@ -22,10 +23,15 @@ class ZeroShotTopicFinder:
"""

model = attr.ib(default='all-MiniLM-L6-v2')
classifier_model = attr.ib(default='valhalla/distilbart-mnli-12-6')


def __attrs_post_init__(self):
self.model = KeyBERT(self.model)

global classifier
classifier = classifier or load_zeroshot_model(self.classifier_model)

def find_topic(self, text, n_topic=2):
"""
Infer the topic in a given string.
Expand Down