[NLP] FastText Python 바인딩 오류 해결하기

2025. 4. 6. 22:29·LLM/Project

이 글은 FastText 사용중에 NumPy 2.0으로 인해 Python 바인딩에서 오류 발생하여 해결한 방법을 공유하고자 작성되었다.

https://c0mputermaster.tistory.com/64

Error

FastText 사용 중, 다음과 같은 오류가 발생했다.

ValueError: Unable to avoid copy while creating an array as requested.
If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)`

 

NumPy 2.0부터 np.array(..., copy=False)의 동작이 변경되어 발생한 문제이다.

 

https://groups.google.com/g/fasttext-library/c/4EOM0-S6xHU?pli=1

 

Fasttext still maintained ? - Numpy compatibility issue

Hi All, I am not aware of any announcements that fasttext is no longer supported. However I just noticed that on Mar 19, 2024 fasttext github repository has been set to a read only archive. Can anyone confirm that this means fasttext is no longer maintaine

groups.google.com

 

 

FastText 더 이상 유지보수되지 않음 (2024년 3월 기준)

  • Meta(구 Facebook)의 공식 FastText GitHub 저장소가 2024년 3월 19일부로 읽기 전용(archived) 처리됨.
  • 사실상 프로젝트 종료, 더 이상 버그 수정, 패치, PR 반영 없음.
  • 공식적인 종료 발표는 없었으나, 저장소 상태로 미루어 종료된 것으로 추정됨.

저장소: https://github.com/facebookresearch/fastText

 

GitHub - facebookresearch/fastText: Library for fast text representation and classification.

Library for fast text representation and classification. - facebookresearch/fastText

github.com

해결방법

첫번째 방법은 레딧에서 대체 라이브러리를 사용하여 문제가 해결되었다고 하여 ( NumPy 2.0 호환이 가능한 fasttext-numpy2 ) 를 사용하여 해결하는 방법을 소개한다.

pip install fasttext-numpy2
  • 기존 FastText와 사용법 동일
  • predict() 함수 오류 해결됨
  • 현재 가장 쉬운 해결 방법

두번째 방법은 허깅스페이스 커뮤티에서 발견한 방법인데 FastText 패키지에 있는 FastText.py를 직접 수정하는 방법이다.

https://huggingface.co/facebook/fasttext-language-identification/discussions/9

 

facebook/fasttext-language-identification · numpy incompatibility

 

huggingface.co

 

원인: NumPy 2.0부터 np.array(..., copy=False)의 동작이 변경됨
→ 이 코드를 np.asarray(...)로 바꿔야 오류가 해결된다.

 

pip install fasttext 가 설치된 경로로 가서 FastText.py를 확인해준다.

수정 전 (문제 있는 코드)  FastText.py에서

return labels, np.array(probs, copy=False)

 

다음과 같이 리턴 타입을 수정

return labels, np.asarray(probs)

 

https://github.com/thomas-ferraz/fastText/commit/0ffafb256d3f6325f8e5dbd527b4e22c1a7e49d2

 

Make FastText.py compatible to numpy >= 2.0 · thomas-ferraz/fastText@0ffafb2

- return np.array(precision, copy=False), np.array(recall, copy=False)

github.com

직접 수정한 버전을 공개한 사용자가 있어 참조하였다.

'LLM > Project' 카테고리의 다른 글

[NLP] FastText로 간단한 텍스트 분류 모델 만들기  (0) 2025.04.02
[Project] LLM을 활용한 시스템 인터페이스 만들어보기  (0) 2025.03.12
'LLM/Project' 카테고리의 다른 글
  • [NLP] FastText로 간단한 텍스트 분류 모델 만들기
  • [Project] LLM을 활용한 시스템 인터페이스 만들어보기
임승택
임승택
"Hello, I am Im Seungtaek, a computer engineering student. Nice to meet you!"
  • Lim's Technology
    임승택
    임승택
    "Welcome to Lim's Technology!"
  • 누적 조회수
    총 회
    구독하기
    • 분류 전체보기 (66)
      • Blog (1)
      • Computer Vision (34)
        • Computer Vision (2)
        • Paper reviews (16)
        • Project (9)
        • Basic (7)
      • LLM (8)
        • Paper reviews (3)
        • Project (3)
        • Basic (2)
      • Data Analysis (7)
        • Basic (7)
      • Robotics (5)
        • Paper reviews (3)
        • Basic (2)
      • Technology Notes (7)
      • Memo (4)
  • 인기 글

  • 최근 댓글

  • 최근 글

임승택
[NLP] FastText Python 바인딩 오류 해결하기
상단으로

티스토리툴바