concision_transformer/codec/
model.rs

1/*
2    Appellation: codec <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use super::{Decoder, Encoder};
6use concision::{builder, getters};
7
8#[derive(Default)]
9pub struct Codec {
10    ctx: Context,
11    decoder: Decoder,
12    encoder: Encoder,
13}
14
15impl Codec {
16    pub fn new() -> CodecBuilder {
17        CodecBuilder::new()
18    }
19
20    getters!(
21        context.ctx<Context>,
22        decoder<Decoder>,
23        encoder<Encoder>,
24    );
25}
26
27builder! {
28    CodecBuilder(Codec) {
29        ctx: Context,
30        decoder: Decoder,
31        encoder: Encoder,
32    }
33}
34
35#[derive(Default)]
36pub struct Generator {
37    pub dmodel: usize,
38    pub vocab: Vec<String>,
39}
40
41#[derive(Default)]
42pub struct Context {
43    pub src: String, // source embedding
44    pub tgt: String, // target embedding
45}
46
47impl Context {
48    pub fn new() -> Self {
49        Self {
50            src: String::new(),
51            tgt: String::new(),
52        }
53    }
54
55    pub fn with_src(self, src: String) -> Self {
56        Self { src, ..self }
57    }
58
59    pub fn with_tgt(self, tgt: String) -> Self {
60        Self { tgt, ..self }
61    }
62}