Spaces:
Sleeping
Sleeping
commit to change the repository to include already trained model and pipeline
Browse filesFiles changed (11)
- .idea/inspectionProfiles/profiles_settings.xmlAdded+6
- .idea/misc.xmlAdded+4
- .idea/modules.xmlAdded+8
- .idea/science-classification.imlAdded+14
- .idea/vcs.xmlAdded+6
- .idea/workspace.xml+13-1
- app.py+17-48
- model_linear_svc.joblibAdded+3
- requirements.txt+1-3
- tfidf_vectorizer.joblibAdded+3
- utils.pyAdded+22
123456<component name="InspectionProjectProfileManager"> <settings> <option name="USE_PROJECT_PROFILE" value="false" /> <version value="1.0" /> </settings></component>1234<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (science-classification)" project-jdk-type="Python SDK" /></project>12345678<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="ProjectModuleManager"> <modules> <module fileurl="file://$PROJECT_DIR$/.idea/science-classification.iml" filepath="$PROJECT_DIR$/.idea/science-classification.iml" /> </modules> </component></project>1234567891011121314<?xml version="1.0" encoding="UTF-8"?><module type="PYTHON_MODULE" version="4"> <component name="NewModuleRootManager"> <content url="file://$MODULE_DIR$"> <excludeFolder url="file://$MODULE_DIR$/venv" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> </component> <component name="PyDocumentationSettings"> <option name="format" value="PLAIN" /> <option name="myDocStringFormat" value="Plain" /> </component></module>123456<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> </component></project>123456723 unmodified lines313233343536<?xml version="1.0" encoding="UTF-8"?><project version="4"><component name="ChangeListManager"><list default="true" id="c9ff8b7d-c1c3-4125-8f84-0a49b7eeea0d" name="Changes" comment="" /><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" /><option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />23 unmodified lines<property name="last_opened_file_path" value="$PROJECT_DIR$" /><property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" /></component><component name="RunManager"><configuration name="app" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"><option name="INTERPRETER_OPTIONS" value="" />123456789101112131423 unmodified lines3839404142434445464748<?xml version="1.0" encoding="UTF-8"?><project version="4"><component name="ChangeListManager"><list default="true" id="c9ff8b7d-c1c3-4125-8f84-0a49b7eeea0d" name="Changes" comment=""><change afterPath="$PROJECT_DIR$/model_linear_svc.joblib" afterDir="false" /><change afterPath="$PROJECT_DIR$/tfidf_vectorizer.joblib" afterDir="false" /><change afterPath="$PROJECT_DIR$/utils.py" afterDir="false" /><change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /><change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" /><change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" /></list><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" /><option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />23 unmodified lines<property name="last_opened_file_path" value="$PROJECT_DIR$" /><property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" /></component><component name="RecentsManager"><key name="CopyFile.RECENT_KEYS"><recent name="C:\Users\borod\OneDrive\Documents\Projects\GitHub\science-classification" /></key></component><component name="RunManager"><configuration name="app" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"><option name="INTERPRETER_OPTIONS" value="" />
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import gradio as grfrom re import subfrom datasets import load_datasetimport pandas as pdfrom sklearn.feature_extraction.text import TfidfVectorizerfrom sklearn.svm import LinearSVCdef clean_text(text):"""Applies some pre-processing on the given text.Steps :- Lowering text- Removing backslashes- removes a. out of the answers- replaces 'b.', 'c.', and 'd.' with comma ','"""text = text.lower()text = text.replace('\\', '') # generic replace was advised by Danittext = text.replace('a.', '')text = text.replace('b.', ',')text = text.replace('c.', ',')text = text.replace('d.', ',')text = sub("\d+", "<num>", text)return ' '.join(text.split())dataset = load_dataset("csv",data_files={"train": "https://huggingface.co/borodache/science-classification-data/resolve/main/subjects-questions.csv"},)df = dataset["train"]# prepare datadf = df[df['category'].isin(['Physics', 'Chemistry', 'Maths', 'Biology'])]questions = df['question']new_questions = []for question in questions:new_questions.append(clean_text(question))X = new_questionsy = df['category']tfidf_vectorizer = TfidfVectorizer(stop_words="english",preprocessor=clean_text,ngram_range=(1, 2))features_tfidf = tfidf_vectorizer.fit_transform(X)# Trainingmodel = LinearSVC()model.fit(features_tfidf, y)def classify(sentence):12345678910111213141516171819202122232425262728import gradio as grfrom sklearn.pipeline import Pipelineimport joblibclass CustomTextClassificationPipeline(Pipeline):def __init__(self):tfidf_vectorizer = joblib.load("tfidf_vectorizer.joblib")linear_svc = joblib.load("model_linear_svc.joblib")super().__init__([('tfidf', tfidf_vectorizer),('classifier', linear_svc)])def predict(self, text):# Call the parent predict method to get the list of predicted labelsy_pred_list = super().predict([text])# Convert the list to a string by taking the first elementy_pred_str = str(y_pred_list[0])return y_pred_strmodel = CustomTextClassificationPipeline()def classify(sentence):
123version https://git-lfs.github.com/spec/v1oid sha256:d7b049ab18b3d50cc79374c0ab9b544ad18807b063c65f82c9fcd62709b0a1fcsize 1775792012345gradiodatasetspandashuggingface_hubscikit-learn123gradioscikit-learnjoblib
123version https://git-lfs.github.com/spec/v1oid sha256:ceb0a87b45261e3cb093b72d2c565dea618c7bd63b9e6f6c16cab1b9a4906d53size 2488198412345678910111213141516171819202122from re import sub
def clean_text(text): """ Applies some pre-processing on the given text.
Steps : - Lowering text - Removing backslashes - removes a. out of the answers - replaces 'b.', 'c.', and 'd.' with comma ',' """ text = text.lower() text = text.replace('\\', '') # generic replace was advised by Danit text = text.replace('a.', '') text = text.replace('b.', ',') text = text.replace('c.', ',') text = text.replace('d.', ',') text = sub("\d+", "<num>", text)
return ' '.join(text.split()).idea/inspectionProfiles/profiles_settings.xmlAdded+6
.idea/misc.xmlAdded+4
.idea/modules.xmlAdded+8
.idea/science-classification.imlAdded+14
.idea/vcs.xmlAdded+6
.idea/workspace.xml+13-1
app.py+17-48
model_linear_svc.joblibAdded+3
requirements.txt+1-3
tfidf_vectorizer.joblibAdded+3
utils.pyAdded+22