mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-08-26 05:36:48 +02:00
.devops
.github
bindings
cmake
coreml
examples
addon.node
bench
bench.wasm
command
command.wasm
lsp
main
python
quantize
server
stream
stream.wasm
sycl
talk
talk-llama
talk.wasm
wchess
whisper.android
whisper.android.java
whisper.nvim
whisper.objc
whisper.swiftui
whisper.wasm
CMakeLists.txt
common-ggml.cpp
common-ggml.h
common-sdl.cpp
common-sdl.h
common.cpp
common.h
dr_wav.h
generate-karaoke.sh
grammar-parser.cpp
grammar-parser.h
helpers.js
json.hpp
livestream.sh
twitch.sh
yt-wsp.sh
ggml-cuda
grammars
models
openvino
samples
scripts
spm-headers
tests
.gitignore
.gitmodules
AUTHORS
CMakeLists.txt
LICENSE
Makefile
Package.swift
README.md
README_sycl.md
ggml-alloc.c
ggml-alloc.h
ggml-backend-impl.h
ggml-backend.c
ggml-backend.h
ggml-common.h
ggml-cuda.cu
ggml-cuda.h
ggml-impl.h
ggml-kompute.cpp
ggml-kompute.h
ggml-metal.h
ggml-metal.m
ggml-metal.metal
ggml-opencl.cpp
ggml-opencl.h
ggml-quants.c
ggml-quants.h
ggml-sycl.cpp
ggml-sycl.h
ggml-vulkan.cpp
ggml-vulkan.h
ggml.c
ggml.h
whisper.cpp
whisper.h
* whisper : add grammar-based sampling * build : fix after master merge * command : fix exception when recognizing the command * whisper : fine-tuning grammar functionality * command : grammar-related improvements - option to read grammar from file - add sample grammars for colors and chess moves - fine-tune the performance further * grammars : add assistant + update comments * command : enable beam-search, add "no_timestamps", add "context", add p * whisper : remove comment --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
30 lines
895 B
C++
30 lines
895 B
C++
// Implements a parser for an extended Backus-Naur form (BNF), producing the
|
|
// binary context-free grammar format specified by whisper.h. Supports character
|
|
// ranges, grouping, and repetition operators. As an example, a grammar for
|
|
// arithmetic might look like:
|
|
//
|
|
// root ::= expr
|
|
// expr ::= term ([-+*/] term)*
|
|
// term ::= num | "(" space expr ")" space
|
|
// num ::= [0-9]+ space
|
|
// space ::= [ \t\n]*
|
|
|
|
#pragma once
|
|
#include "whisper.h"
|
|
#include <vector>
|
|
#include <map>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace grammar_parser {
|
|
struct parse_state {
|
|
std::map<std::string, uint32_t> symbol_ids;
|
|
std::vector<std::vector<whisper_grammar_element>> rules;
|
|
|
|
std::vector<const whisper_grammar_element *> c_rules() const;
|
|
};
|
|
|
|
parse_state parse(const char * src);
|
|
void print_grammar(FILE * file, const parse_state & state);
|
|
}
|