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)
- Running Keybert for a list of docs to extract arabic keywords HOT 1
- KeyLLM - page_content error with bedrock model HOT 3
- Efficient KeyLLM + KeyBERT - Torch not compiled with CUDA enabled HOT 1
- Allow KeyBERT to pass `batch_size` to `llm.encode()` method HOT 5
- Make system content as variable HOT 2
- Fail to parse OpenAI api response HOT 2
- Extract keywords from multiple documents given a nested list of candidates for each document. HOT 1
- can't import keybert HOT 9
- Using KeyBERT with a locally saved model HOT 1
- Not able to use gensim HOT 5
- Why and how the same model for doc_embeddings and word_embeddings? HOT 1
- Setup check. Script to get keywords for comparing against SimpleMaths, TextRank and Philology results HOT 5
- Add more LLMs HOT 1
- OSError: libcudart.so.12: cannot open shared object file: No such file or directory HOT 2
- KeyLLM error: AttributeError: 'str' object has no attribute 'completions' HOT 9
- KeyLLM Error: AttributeError: 'CompletionChoice' object has no attribute 'message' HOT 6
- CLI tool like YAKE
- keybert benchmarks with respect to other phrase extraction techniques. HOT 1
- Drop support for Python < 3.8 HOT 5
- pre-commit-hooks: replace black and flake8 HOT 2
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.