-
Notifications
You must be signed in to change notification settings - Fork 14
/
model.ex
52 lines (39 loc) 路 1.42 KB
/
model.ex
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Tokenizers.Model do
@moduledoc """
The struct and associated functions for the tokenizer model.
"""
defstruct [:resource]
@typedoc """
Represents different kind of models that can be used across the library.
"""
@type t() :: %__MODULE__{resource: reference()}
@doc """
Retrieves information about the model.
Information retrieved differs per model but all include `model_type`.
"""
@spec info(t()) :: map()
defdelegate info(model), to: Tokenizers.Native, as: :models_info
@doc """
Saves the given model in the given directory.
This function generates a couple files with predefined names, you
can specify `:prefix` to scope them. Existing files with the same
names in this directory will be overridden.
## Options
* `:prefix` - the prefix to use for all the files that will get
created. Defaults to `""`
"""
@spec save(t(), String.t(), keyword()) :: {:ok, file_paths :: [String.t()]} | {:error, any()}
defdelegate save(model, directory, opts \\ []), to: Tokenizers.Native, as: :models_save
end
defimpl Inspect, for: Tokenizers.Model do
import Inspect.Algebra
alias Tokenizers.Model
@spec inspect(Tokenizers.Model.t(), Inspect.Opts.t()) :: Inspect.Algebra.t()
def inspect(model, opts) do
attrs =
model
|> Model.info()
|> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end)
concat(["#Tokenizers.Model<", to_doc(attrs, opts), ">"])
end
end