• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17// Flatbuffer schema for SAFT models.
18//
19// For info on flatbuffers, see http://go/flatbuffers and
20// http://google.github.io/flatbuffers/, including info on writing schemas:
21// http://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html
22
23namespace libtextclassifier3.saft_fbs;
24
25// SM stands for Saft Model.  The next two digits are meant to identify
26// incompatible versions.  Ideally, we'll never have to go beyond 00.
27file_identifier "SM00";
28
29// Extension stands for Saft Model in FlatBuffer format.
30file_extension "smfb";
31
32table ModelParameter {
33  // Parameter name.
34  name:string;
35
36  // Parameter value.
37  value:string;
38}
39
40// Input for a SAFT model.  Inputs usually provide extra resources: e.g., the
41// parameters for a Neurosis FFNN with embeddings, or a word cluster structure,
42// etc.
43table ModelInput {
44  // Name of this input.  Different input of the same model should have
45  // different names, such that we can non-ambiguously look them up.
46  name:string;
47
48  // General description of the type of this input.  Required to parse the
49  // content of this input (see |data| below).  If |data| is a flatbuffer, use
50  // "flatbuffer".  If |data| is a proto, use "proto".  Otherwise, use your best
51  // judgment: use something human-readable, and look around to make sure you
52  // don't invent a new name for something that already exists.
53  type:string;
54
55  // More specific information about the type of this input.  E.g., if |type| is
56  // "flatbuffer", this should be the name of the root_type we should parse from
57  // the input bytes., e.g., "EmbeddingNetwork".  If |type| is proto, this
58  // should be the name of the proto serialized as |data|, e.g.,
59  // "EmbeddingNetworkProto".
60  sub_type:string;
61
62  // The content of this input.  With a generous alignment, such that we can
63  // accommodate mmap-friendly data structures.  E.g., the word clusters used by
64  // the Translate team require 8-byte alignment.
65  data:[ubyte] (force_align: 16);
66}
67
68// A Saft model.  A list of parameters with model settings (e.g., the
69// specification of the features to use) and a list of inputs.
70table Model {
71  parameters:[ModelParameter];
72  inputs:[ModelInput];
73
74  // Crc32 checksum of all parameters and inputs (including the bytes of the
75  // inputs).  Used to check that the model has not been corrupted.
76  crc32:uint32;
77}
78
79root_type Model;
80