Comments (6)
Could you share the code you have been using? This allows me to create a reproducible example and hopefully fix the issue you are having.
from keybert.
Excuse me, I tried two ways to use keybert: Fast and Flask. (1) When I use keybert by Fast(multi-thread on a computer), The error "runtime error: already borrowed" did not occurrred. But error "runtime error Default CPUAllocator: not enough memory: you tried to allocate 196608 byte" (my computer has 256M memory, two thread run on it). (2) When I use keybert by Flask (multi-thread on a computer), The error "runtime error: already borrowed" occurred. But the error about memory allocator did not occurred. The following is my code. Thank you very much.
(1) Fast
from fastapi import Depends, FastAPI
from pydantic import BaseModel
app = FastAPI()
kw_model=KeyBERT()
class KeywordRequest(BaseModel):
text: str
num: Optional[int] = 10
ngram_lo: Optional[int] = 1
ngram_hi: Optional[int] = 2
diversity: Optional[float] = 0.6
@app.post('/keywords')
def index(
keyword_request: KeywordRequest,
):
keywords = kw_model.extract_keywords(keyword_request.text,keyphrase_ngram_range=(1,2), stop_words='english',top_n=keyword_request.num)
result={'isSuc':'true', 'errMsg':'null'}
stringindex=[]
for x in keywords:
detail_res_dic = {}
detail_res_dic['phrase']=x[0]
detail_res_dic['weight']=x[1]
stringindex.append(detail_res_dic)
result['res']=stringindex
return json.dumps(result,ensure_ascii=False)
(2)Flask
import flask
import json
from keybert import KeyBERT
server = flask.Flask(name)
strs='123456'
print("加载。。。")
kw_model=KeyBERT()
@server.route('/index',methods=['get','post'])
def index():
text=flask.request.values.get('text')
num_str= flask.request.values.get('num')
num=int(num_str)
keywords = kw_model.extract_keywords(text,keyphrase_ngram_range=(1,2), stop_words='english',top_n=num)
result={'isSuc':'true', 'errMsg':'null'}
stringindex=[]
for x in keywords:
detail_res_dic = {}
detail_res_dic['phrase']=x[0]
detail_res_dic['weight']=x[1]
stringindex.append(detail_res_dic)
result['res']=stringindex
return json.dumps(result,ensure_ascii=False)
server.run(port=7777,debug=True,host='0.0.0.0')
from keybert.
How did you exactly call both servers? In other words, could you share exactly how you started the servers and how you did the POST? For example, did you start the FastAPI server with uvicorn main:app --reload
? And how did you do your POST method, was it through Postman or something else?
However, these models are not meant to be multi-threaded which can explain the issues you are having. Extracting keywords that are generated through embedding models is difficult to multi-thread/parallelize which can explain your issues.
from keybert.
I do my POST method just on my computer. I use the localhost as server. I start the FastAPI server with
uvicorn --hoset 0.0.0.0 --port 5000 main:app
The two servers is the same computer. I first use it by FAST, When I got the error, I stop and try Flask to test.
from keybert.
I just tried it out in a fresh environment and had no issues with the following code:
from fastapi import FastAPI
from keybert import KeyBERT
app = FastAPI()
kw_model=KeyBERT()
@app.get('/keywords')
def index(text: str):
keywords = kw_model.extract_keywords(text, keyphrase_ngram_range=(1,2), stop_words='english')
return keywords
Using that code in main.py
I ran the following both in the browser and in Postman:
http://127.0.0.1:8000/keywords/?text="This is a piece of text that has some interesting values."
Try using the code above and see if that works. However, it might be interesting to look into using an embedder that uses less memory since you have very little memory that you can use. These models typically require a bit more.
from keybert.
I will close this for now seeing as there hasn't been an update. However, feel free to re-open it if you are still experiencing this issue!
from keybert.
Related Issues (20)
- Excluding certain words HOT 1
- KeyLLM keyword extraction issue HOT 6
- Keywords are all lowercase HOT 2
- Segmentation Fault While Running in Docker HOT 5
- How can I use the KeyBERT if I have tokenized Chinese documents by myself? HOT 1
- KeyLLM seems to use OpenAI parameters that are deprecated HOT 13
- Does KeyBERT support openai ada embedding? HOT 1
- KeyBERT with llm and embedding model: endless loop during extract_keywords HOT 4
- Question about KeyLLM + KeyBERT HOT 6
- Bug: possible mistake in MMR calculation HOT 1
- Cohere default model HOT 3
- importing KeyBERT causes pydantic_core problems HOT 3
- KeyLLM fails when no GPU is available HOT 1
- extraction of keywords should be ignored when the LLM does not know or does not find them HOT 2
- Is there a batched-based keyword extraction approach with keyBERT? HOT 2
- KeyLLM error with bedrock model HOT 9
- KeyLLM parameter control HOT 3
- Langchain produces error based on instructions in sourcecode HOT 1
- Stopwords on KeyBERT HOT 6
- KeyLLM - Mistral token issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keybert.