File size: 782 Bytes
e4b9a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0


class MultiEL:
    def __init__(self, model_name="bela", device="cuda"):
        self.model_name = model_name
        self.device = device
        self.load_model()

    def load_model(self):
        try:
            from multiel import BELA
        except ImportError as exc:
            raise ImportError(
                "Can't import multiel package, you can install by pip install multiel."
            ) from exc
        self._bela_run = BELA(device=self.device)

    def process_batch(self, list_text):
        if isinstance(list_text, str):
            list_text = [list_text]
        return self._bela_run.process_batch(list_text)