sequence

package
v0.0.0-...-3b1b184 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	AdditionTxt = "addition.txt"
	DateTxt     = "date.txt"
)

Variables

This section is empty.

Functions

func Load

func Load(dir, fileName string, s ...randv2.Source) (*Dataset, *Dataset, *Vocab, error)
Example
package main

import (
	"fmt"

	"github.com/itsubaki/neu/dataset/sequence"
	"github.com/itsubaki/neu/math/rand"
)

func main() {
	s := rand.Const(1)
	x, t, v := sequence.Must(sequence.Load("../../testdata", sequence.AdditionTxt, s))

	fmt.Println(len(x.Train), len(x.Train[0]), len(x.Test), len(x.Test[0]))
	fmt.Println(len(t.Train), len(t.Train[0]), len(t.Test), len(t.Test[0]))
	fmt.Println(len(v.IDToRune), len(v.RuneToID))
	fmt.Println(x.Train[0], t.Train[0])
	fmt.Println(v.ToString(x.Train[0]), v.ToString(t.Train[0]))

}
Output:

45000 7 5000 7
45000 5 5000 5
13 13
[9 0 3 2 7 5 5] [12 9 0 3 5]
[9 1 7 + 0    ] [_ 9 1 7  ]
Example (Notfound)
package main

import (
	"fmt"

	"github.com/itsubaki/neu/dataset/sequence"
)

func main() {
	_, _, _, err := sequence.Load("invalid_dir", "invlid_file")
	fmt.Println(err)

}
Output:

open file=invalid_dir/invlid_file: open invalid_dir/invlid_file: no such file or directory
Example (Rand)
package main

import (
	"fmt"

	"github.com/itsubaki/neu/dataset/sequence"
)

func main() {
	x, t, v := sequence.Must(sequence.Load("../../testdata", sequence.AdditionTxt))

	fmt.Println(len(x.Train), len(x.Train[0]), len(x.Test), len(x.Test[0]))
	fmt.Println(len(t.Train), len(t.Train[0]), len(t.Test), len(t.Test[0]))
	fmt.Println(len(v.IDToRune), len(v.RuneToID))

}
Output:

45000 7 5000 7
45000 5 5000 5
13 13

func Must

func Must(train, test *Dataset, vocab *Vocab, err error) (*Dataset, *Dataset, *Vocab)

Types

type Dataset

type Dataset struct {
	Train [][]int
	Test  [][]int
}

type Vocab

type Vocab struct {
	RuneToID map[rune]int
	IDToRune map[int]rune
}

func (Vocab) ID

func (v Vocab) ID(words []string) [][]int

func (Vocab) Rune

func (v Vocab) Rune(x []int) []rune

func (Vocab) ToString

func (v Vocab) ToString(x []int) []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL