From 8c7b7e5feb68fda1fc4ddd627bad0f915358149e Mon Sep 17 00:00:00 2001
From: Zhanzhao (Deo) Liang <liangzhanzhao1985@gmail.com>
Date: 星期三, 25 十二月 2024 16:40:29 +0800
Subject: [PATCH] fix export_meta import of sense voice (#2334)

---
 docs/tutorial/Tables_zh.md |  143 +++++++++++++++++++++++++++--------------------
 1 files changed, 83 insertions(+), 60 deletions(-)

diff --git a/docs/tutorial/Tables_zh.md b/docs/tutorial/Tables_zh.md
index 9f616cf..e9360e0 100644
--- a/docs/tutorial/Tables_zh.md
+++ b/docs/tutorial/Tables_zh.md
@@ -1,39 +1,21 @@
-# FunASR-1.x.x聽娉ㄥ唽妯″瀷鏁欑▼
+# FunASR-1.x.x聽娉ㄥ唽鏂版ā鍨嬫暀绋�
 
-1.0鐗堟湰鐨勮璁″垵琛锋槸銆�**璁╂ā鍨嬮泦鎴愭洿绠�鍗�**銆戯紝鏍稿績feature涓烘敞鍐岃〃涓嶢utoModel锛�
+(绠�浣撲腑鏂噟[English](./Tables.md))
+
+funasr-1.x.x聽鐗堟湰鐨勮璁″垵琛锋槸銆�**璁╂ā鍨嬮泦鎴愭洿绠�鍗�**銆戯紝鏍稿績feature涓烘敞鍐岃〃涓嶢utoModel锛�
 
 *   娉ㄥ唽琛ㄧ殑寮曞叆锛屼娇寰楀紑鍙戜腑鍙互鐢ㄦ惌绉湪鐨勬柟寮忔帴鍏ユā鍨嬶紝鍏煎澶氱task锛�
-    
-*   鏂拌璁$殑AutoModel鎺ュ彛锛岀粺涓�modelscope銆乭uggingface涓巉unasr鎺ㄧ悊涓庤缁冩帴鍙o紝鏀寔鑷敱閫夋嫨涓嬭浇浠撳簱锛�
-    
-*   鏀寔妯″瀷瀵煎嚭锛宒emo绾у埆鏈嶅姟閮ㄧ讲锛屼互鍙婂伐涓氱骇鍒骞跺彂鏈嶅姟閮ㄧ讲锛�
-    
-*   缁熶竴瀛︽湳涓庡伐涓氭ā鍨嬫帹鐞嗚缁冭剼鏈紱
-    
 
-![image](https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/a/6Ea1DxkZVte8y0g2/150e0eafd1c34f2dbb9360ccb5db4dc40521.png)
+*   鏂拌璁$殑AutoModel鎺ュ彛锛岀粺涓�modelscope銆乭uggingface涓巉unasr鎺ㄧ悊涓庤缁冩帴鍙o紝鏀寔鑷敱閫夋嫨涓嬭浇浠撳簱锛�
+
+*   鏀寔妯″瀷瀵煎嚭锛宒emo绾у埆鏈嶅姟閮ㄧ讲锛屼互鍙婂伐涓氱骇鍒骞跺彂鏈嶅姟閮ㄧ讲锛�
+
+*   缁熶竴瀛︽湳涓庡伐涓氭ā鍨嬫帹鐞嗚缁冭剼鏈紱
+
 
 # 蹇�熶笂鎵�
 
 ## 鍩轰簬automodel鐢ㄦ硶
-
-### Paraformer妯″瀷
-
-杈撳叆浠绘剰鏃堕暱璇煶锛岃緭鍑轰负璇煶鍐呭瀵瑰簲鏂囧瓧锛屾枃瀛楀叿鏈夋爣鐐规柇鍙ワ紝瀛楃骇鍒椂闂存埑锛屼互鍙婅璇濅汉韬唤銆�
-
-```python
-from funasr import AutoModel
-
-model = AutoModel(model="paraformer-zh",  
-                  vad_model="fsmn-vad", 
-                  vad_kwargs={"max_single_segment_time": 60000},
-                  punc_model="ct-punc", 
-                  # spk_model="cam++"
-                  )
-wav_file = f"{model.model_path}/example/asr_example.wav"
-res = model.generate(input=wav_file, batch_size_s=300, batch_size_threshold_s=60, hotword='榄旀惌')
-print(res)
-```
 
 ### SenseVoiceSmall妯″瀷
 
@@ -69,19 +51,19 @@
 ```
 
 *   `model`(str):聽[妯″瀷浠撳簱](https://github.com/alibaba-damo-academy/FunASR/tree/main/model_zoo)聽涓殑妯″瀷鍚嶇О锛屾垨鏈湴纾佺洏涓殑妯″瀷璺緞
-    
+
 *   `device`(str):聽`cuda:0`锛堥粯璁pu0锛夛紝浣跨敤聽GPU聽杩涜鎺ㄧ悊锛屾寚瀹氥�傚鏋滀负`cpu`锛屽垯浣跨敤聽CPU聽杩涜鎺ㄧ悊
-    
+
 *   `ncpu`(int):聽`4`聽锛堥粯璁わ級锛岃缃敤浜幝燙PU聽鍐呴儴鎿嶄綔骞惰鎬х殑绾跨▼鏁�
-    
+
 *   `output_dir`(str):聽`None`聽锛堥粯璁わ級锛屽鏋滆缃紝杈撳嚭缁撴灉鐨勮緭鍑鸿矾寰�
-    
+
 *   `batch_size`(int):聽`1`聽锛堥粯璁わ級锛岃В鐮佹椂鐨勬壒澶勭悊锛屾牱鏈釜鏁�
-    
+
 *   `hub`(str)锛歚ms`锛堥粯璁わ級锛屼粠modelscope涓嬭浇妯″瀷銆傚鏋滀负`hf`锛屼粠huggingface涓嬭浇妯″瀷銆�
-    
+
 *   `**kwargs`(dict):聽鎵�鏈夊湪`config.yaml`涓弬鏁帮紝鍧囧彲浠ョ洿鎺ュ湪姝ゅ鎸囧畾锛屼緥濡傦紝vad妯″瀷涓渶澶у垏鍓查暱搴β燻max_single_segment_time=6000`聽锛堟绉掞級銆�
-    
+
 
 #### AutoModel聽鎺ㄧ悊
 
@@ -90,13 +72,13 @@
 ```
 
 *   *   wav鏂囦欢璺緞,聽渚嬪:聽asr\_example.wav
-        
+
     *   pcm鏂囦欢璺緞,聽渚嬪:聽asr\_example.pcm锛屾鏃堕渶瑕佹寚瀹氶煶棰戦噰鏍风巼fs锛堥粯璁や负16000锛�
-        
+
     *   闊抽瀛楄妭鏁版祦锛屼緥濡傦細楹﹀厠椋庣殑瀛楄妭鏁版暟鎹�
-        
+
     *   wav.scp锛宬aldi聽鏍峰紡鐨劼爓av聽鍒楄〃聽(`wav_id聽\t聽wav_path`),聽渚嬪:
-        
+
 
 ```plaintext
 asr_example1  ./audios/asr_example1.wav
@@ -107,23 +89,27 @@
 鍦ㄨ繖绉嶈緭鍏ヂ�
 
 *   闊抽閲囨牱鐐癸紝渚嬪锛歚audio,聽rate聽=聽soundfile.read("asr_example_zh.wav")`,聽鏁版嵁绫诲瀷涓郝爊umpy.ndarray銆傛敮鎸乥atch杈撳叆锛岀被鍨嬩负list锛毬燻[audio_sample1,聽audio_sample2,聽...,聽audio_sampleN]`
-    
+
 *   fbank杈撳叆锛屾敮鎸佺粍batch銆俿hape涓篭[batch,聽frames,聽dim\]锛岀被鍨嬩负torch.Tensor锛屼緥濡�
-    
+
 *   `output_dir`:聽None聽锛堥粯璁わ級锛屽鏋滆缃紝杈撳嚭缁撴灉鐨勮緭鍑鸿矾寰�
-    
+
 *   `**kwargs`(dict):聽涓庢ā鍨嬬浉鍏崇殑鎺ㄧ悊鍙傛暟锛屼緥濡傦紝`beam_size=10`锛宍decoding_ctc_weight=0.1`銆�
-    
+
 
 璇︾粏鏂囨。閾炬帴锛歔https://github.com/modelscope/FunASR/blob/main/examples/README\_zh.md](https://github.com/modelscope/FunASR/blob/main/examples/README_zh.md)
 
 # 娉ㄥ唽琛ㄨ瑙�
 
+浠enseVoiceSmall妯″瀷涓轰緥锛岃瑙e浣曟敞鍐屾柊妯″瀷锛屾ā鍨嬮摼鎺ワ細
+
+**modelscope锛�**[https://www.modelscope.cn/models/iic/SenseVoiceSmall/files](https://www.modelscope.cn/models/iic/SenseVoiceSmall/files)
+
+**huggingface锛�**[https://huggingface.co/FunAudioLLM/SenseVoiceSmall](https://huggingface.co/FunAudioLLM/SenseVoiceSmall)
+
 ## 妯″瀷璧勬簮鐩綍
 
 ![image.png](https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/8oLl9y628rBNlapY/img/cab7f215-787f-4407-885a-14dc89ae9e02.png)
-
-**妯″瀷閾炬帴涓猴細**[https://www.modelscope.cn/models/iic/SenseVoiceSmall/files](https://www.modelscope.cn/models/iic/SenseVoiceSmall/files)
 
 **閰嶇疆鏂囦欢**锛歝onfig.yaml
 
@@ -142,7 +128,7 @@
     pos_enc_class: SinusoidalPositionEncoder
     normalize_before: true
     kernel_size: 11
-    sanm_shfit: 0
+    sanm_shift: 0
     selfattention_layer_type: sanm
 
 
@@ -213,7 +199,7 @@
 
 **妯″瀷鍙傛暟**锛歮odel.pt
 
-**璺緞瑙f瀽**锛歝onfiguration.json
+**璺緞瑙f瀽**锛歝onfiguration.json锛堥潪蹇呴渶锛�
 
 ```json
 {
@@ -222,19 +208,31 @@
   "model": {"type" : "funasr"},
   "pipeline": {"type":"funasr-pipeline"},
   "model_name_in_hub": {
-    "ms":"", 
+    "ms":"",
     "hf":""},
   "file_path_metas": {
-    "init_param":"model.pt", 
+    "init_param":"model.pt",
     "config":"config.yaml",
     "tokenizer_conf": {"bpemodel": "chn_jpn_yue_eng_ko_spectok.bpe.model"},
     "frontend_conf":{"cmvn_file": "am.mvn"}}
 }
 ```
 
-鍐呭鍙互澶嶇敤锛岀洿鎺ユ嫹璐濆嵆鍙紝闇�瑕佹敞鎰忓瓧娈� `file_path_metas` 鎵�鏈夊唴瀹逛細鑷姩鎷兼帴妯″瀷璧勬簮璺緞锛屽苟涓斾細瑕嗙洊 `config.yaml` 涓浉鍚屽瓧娈电殑璺緞銆�
+configuration.json鐨勪綔鐢ㄦ槸缁檉ile\_path\_metas涓殑item鎷兼帴涓婃ā鍨嬫牴鐩綍锛屼互渚夸簬璺緞鑳藉琚纭殑瑙f瀽锛屼互涓婁负渚嬶紝鍋囪妯″瀷鏍圭洰褰曚负锛�/home/zhifu.gzf/init\_model/SenseVoiceSmall锛岀洰褰曚腑config.yaml涓殑鐩稿叧璺緞琚浛鎹㈡垚浜嗘纭殑璺緞锛堝拷鐣ユ棤鍏抽厤缃級锛�
+
+```yaml
+init_param: /home/zhifu.gzf/init_model/SenseVoiceSmall/model.pt
+
+tokenizer_conf:
+  bpemodel: /home/zhifu.gzf/init_model/SenseVoiceSmall/chn_jpn_yue_eng_ko_spectok.bpe.model
+
+frontend_conf:
+    cmvn_file: /home/zhifu.gzf/init_model/SenseVoiceSmall/am.mvn
+```
 
 ## 娉ㄥ唽琛�
+
+![image](https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/a/6Ea1DxkZVte8y0g2/c92059e82c38493988fbc8c032d3f5380521.png)
 
 ### 鏌ョ湅娉ㄥ唽琛�
 
@@ -244,7 +242,24 @@
 tables.print()
 ```
 
-鏀寔鏌ョ湅鎸囧畾绫诲瀷鐨勬敞鍐岃〃锛屼緥濡傚彧鐪嬫敞鍐岀殑`model`绫伙細`tables.print("model")`
+鏀寔鏌ョ湅鎸囧畾绫诲瀷鐨勬敞鍐岃〃锛歕`tables.print("model")\`锛岀洰鍓峟unasr宸茬粡娉ㄥ唽妯″瀷濡備笂鍥炬墍绀恒�傜洰鍓嶉鍏堝畾涔変簡濡備笅鍑犱釜鍒嗙被锛�
+
+```python
+    model_classes = {}
+    frontend_classes = {}
+    specaug_classes = {}
+    normalize_classes = {}
+    encoder_classes = {}
+    decoder_classes = {}
+    joint_network_classes = {}
+    predictor_classes = {}
+    stride_conv_classes = {}
+    tokenizer_classes = {}
+    dataloader_classes = {}
+    batch_sampler_classes = {}
+    dataset_classes = {}
+    index_ds_classes = {}
+```
 
 ### 娉ㄥ唽妯″瀷
 
@@ -259,7 +274,7 @@
   def forward(
       self,
       **kwargs,
-  ):  
+  ):
 
   def inference(
       self,
@@ -274,7 +289,15 @@
 
 ```
 
-鍦ㄩ渶瑕佹敞鍐岀殑绫诲悕鍓嶅姞涓� `@tables.register("model_classes","SenseVoiceSmall")`锛屽嵆鍙畬鎴愭敞鍐岋紝绫婚渶瑕佸疄鐜版湁锛歘_init__锛宖orward锛宨nference鏂规硶銆�
+鍦ㄩ渶瑕佹敞鍐岀殑绫诲悕鍓嶅姞涓娐燖tables.register("model\_classes",聽"SenseVoiceSmall")锛屽嵆鍙畬鎴愭敞鍐岋紝绫婚渶瑕佸疄鐜版湁锛歕_\_init\_\_锛宖orward锛宨nference鏂规硶銆�
+
+register鐢ㄦ硶锛�
+
+```python
+@tables.register("娉ㄥ唽鍒嗙被", "娉ㄥ唽鍚�")
+```
+
+鍏朵腑锛�"娉ㄥ唽鍒嗙被"鍙互鏄鍏堝畾涔夊ソ鐨勫垎绫伙紙瑙佷笂闈㈠浘锛夛紝濡傛灉鏄嚜宸卞畾涔夌殑鏂板垎绫伙紝浼氳嚜鍔ㄥ皢鏂板垎绫诲啓杩涙敞鍐岃〃鍒嗙被涓紝"娉ㄥ唽鍚�"鍗冲笇鏈涙敞鍐屽悕瀛楋紝鍚庣画鍙互鐩存帴鏉ヤ娇鐢ㄣ��
 
 瀹屾暣浠g爜锛歔https://github.com/modelscope/FunASR/blob/main/funasr/models/sense\_voice/model.py#L443](https://github.com/modelscope/FunASR/blob/main/funasr/models/sense_voice/model.py#L443)
 
@@ -286,9 +309,9 @@
   ...
 ```
 
-## 娉ㄥ唽澶辫触
+### 娉ㄥ唽澶辫触
 
-濡傛灉鍑虹幇鎵句笉鍒版敞鍐屾ā鍨嬫垨鑰呮敞鍐屽嚱鏁帮紝`assert model_class is not None, f'{kwargs["model"]} is not registered'`銆傛ā鍨嬫敞鍐岀殑鍘熺悊鏄紝import 妯″瀷鏂囦欢锛屽彲浠ラ�氳繃import鏉ユ煡鐪嬪叿浣撴敞鍐屽け璐ュ師鍥狅紝渚嬪锛屼笂杩版ā鍨嬫枃浠朵负锛宖unasr/models/sense_voice/model.py锛�
+濡傛灉鍑虹幇鎵句笉鍒版敞鍐屾ā鍨嬫垨鍙戞柟娉曪紝assert聽model\_class聽is聽not聽None,聽f'{kwargs\["model"\]}聽is聽not聽registered'銆傛ā鍨嬫敞鍐岀殑鍘熺悊鏄紝import聽妯″瀷鏂囦欢锛屽彲浠ラ�氳繃import鏉ユ煡鐪嬪叿浣撴敞鍐屽け璐ュ師鍥狅紝渚嬪锛屼笂杩版ā鍨嬫枃浠朵负锛宖unasr/models/sense\_voice/model.py锛�
 
 ```python
 from funasr.models.sense_voice.model import *
@@ -297,9 +320,9 @@
 ## 娉ㄥ唽鍘熷垯
 
 *   Model锛氭ā鍨嬩箣闂翠簰鐩哥嫭绔嬶紝姣忎竴涓ā鍨嬶紝閮介渶瑕佸湪funasr/models/涓嬮潰鏂板缓涓�涓ā鍨嬬洰褰曪紝涓嶈閲囩敤绫荤殑缁ф壙鏂规硶锛侊紒锛佷笉瑕佷粠鍏朵粬妯″瀷鐩綍涓璱mport锛屾墍鏈夐渶瑕佺敤鍒扮殑閮藉崟鐙斁鍒拌嚜宸辩殑妯″瀷鐩綍涓紒锛侊紒涓嶈淇敼鐜版湁鐨勬ā鍨嬩唬鐮侊紒锛侊紒
-    
+
 *   dataset锛宖rontend锛宼okenizer锛屽鏋滆兘澶嶇敤鐜版湁鐨勶紝鐩存帴澶嶇敤锛屽鏋滀笉鑳藉鐢紝璇锋敞鍐屼竴涓柊鐨勶紝鍐嶄慨鏀癸紝涓嶈淇敼鍘熸潵鐨勶紒锛侊紒
-    
+
 
 # 鐙珛浠撳簱
 
@@ -313,8 +336,8 @@
 # trust_remote_code锛歚True` 琛ㄧず model 浠g爜瀹炵幇浠� `remote_code` 澶勫姞杞斤紝`remote_code` 鎸囧畾 `model` 鍏蜂綋浠g爜鐨勪綅缃紙渚嬪锛屽綋鍓嶇洰褰曚笅鐨� `model.py`锛夛紝鏀寔缁濆璺緞涓庣浉瀵硅矾寰勶紝浠ュ強缃戠粶 url銆�
 model = AutoModel(
     model="iic/SenseVoiceSmall",
-    trust_remote_code=True,  
-    remote_code="./model.py", 
+    trust_remote_code=True,
+    remote_code="./model.py",
 )
 ```
 
@@ -337,4 +360,4 @@
 print(text)
 ```
 
-寰皟鍙傝�冿細[https://github.com/FunAudioLLM/SenseVoice/blob/main/finetune.sh](https://github.com/FunAudioLLM/SenseVoice/blob/main/finetune.sh)
\ No newline at end of file
+寰皟鍙傝�冿細[https://github.com/FunAudioLLM/SenseVoice/blob/main/finetune.sh](https://github.com/FunAudioLLM/SenseVoice/blob/main/finetune.sh)

--
Gitblit v1.9.1