I’m working on a project using a Raspberry Pi 4B (4GB RAM) and facing issues when running a Python script that uses DistilBERT and Okt (from the Konlpy library). Below is a simplified version of the code I’m working with:
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
import torch
from konlpy.tag import Okt
class IntentDetector:
def __init__(self):
self.model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-multilingual-cased')
self.tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-multilingual-cased')
self.komoran = Okt()
def recognize_intent_and_destination(self, text):
input_text = self.preprocess_text(text)
input_ids = torch.tensor([self.tokenizer.encode(input_text)])
with torch.no_grad():
output = self.model(input_ids)[0]
tokens = self.komoran.pos(input_text)
destination = self.extract_destination(tokens)
return tokens, destination
# Test
intent_detector = IntentDetector()
intent_detector.recognize_intent_and_destination("강남역 가는 노선 알려줘")
When I try to run the script, I get a “command not found” error, and the script fails to execute properly. Here’s the key part of the error log:
SyntaxError: invalid syntax
명령어가 잘못됨
I have tried the following steps to troubleshoot:
- Reinstalled
torch
,transformers
, andkonlpy
. - Increased swap memory on the Raspberry Pi to 2048 MB to handle large model loads.
- Verified that
torch
is installed using the correct version for ARM architecture.
Despite these efforts, the issue remains. I suspect it might be related to memory limitations or library compatibility on the Raspberry Pi.
Any suggestions or guidance would be appreciated. Thank you in advance!