From e7124915b6db38e63e08fb64dbad79386ba26d49 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期三, 26 七月 2023 19:02:02 +0800
Subject: [PATCH] docs zh

---
 docs/installation/installation_zh.md       |   75 ++++++++++
 docs/modelscope_pipeline/quick_start_zh.md |  227 ++++++++++++++++++++++++++++++++
 docs/installation/docker.md                |    2 
 docs/installation/installation.md          |    6 
 docs/modelscope_pipeline/quick_start.md    |    5 
 docs/installation/docker_zh.md             |   72 ++++++++++
 6 files changed, 383 insertions(+), 4 deletions(-)

diff --git a/docs/installation/docker.md b/docs/installation/docker.md
index 24b1532..8de3390 100644
--- a/docs/installation/docker.md
+++ b/docs/installation/docker.md
@@ -1,3 +1,5 @@
+([绠�浣撲腑鏂嘳(./docker_zh.md)|English)
+
 # Docker
 
 ## Install Docker
diff --git a/docs/installation/docker_zh.md b/docs/installation/docker_zh.md
new file mode 100644
index 0000000..74f303e
--- /dev/null
+++ b/docs/installation/docker_zh.md
@@ -0,0 +1,72 @@
+(绠�浣撲腑鏂噟[English](./docker.md))
+
+# Docker
+
+## 瀹夎Docker
+
+### Ubuntu
+```shell
+curl -fsSL https://test.docker.com -o test-docker.sh
+sudo sh test-docker.sh
+```
+### Debian
+```shell
+ curl -fsSL https://get.docker.com -o get-docker.sh
+ sudo sh get-docker.sh
+```
+
+### CentOS
+```shell
+curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
+```
+
+### MacOS
+```shell
+brew install --cask --appdir=/Applications docker
+```
+
+### Windows
+璇峰弬鑰僛鏂囨。](https://docs.docker.com/desktop/install/windows-install/)
+
+## 鍚姩Docker
+```shell
+sudo systemctl start docker
+```
+## 涓嬭浇Docker闀滃儚
+
+### 闀滃儚浠撳簱
+
+#### CPU
+`registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.1.0`
+
+#### GPU
+
+`registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.7.0`
+
+### 鎷夊彇闀滃儚
+```shell
+sudo docker pull <image-name>:<tag>
+```
+
+### 鏌ョ湅闀滃儚
+```shell
+sudo docker images
+```
+
+## 杩愯Docker
+```shell
+# cpu
+sudo docker run -itd --name funasr -v <local_dir:dir_in_docker> <image-name>:<tag> /bin/bash
+# gpu
+sudo docker run -itd --gpus all --name funasr -v <local_dir:dir_in_docker> <image-name>:<tag> /bin/bash
+
+sudo docker exec -it funasr /bin/bash
+```
+
+## 鍋滄Docker
+```shell
+exit
+sudo docker ps
+sudo docker stop funasr
+```
+
diff --git a/docs/installation/installation.md b/docs/installation/installation.md
index f81ae83..43856cd 100755
--- a/docs/installation/installation.md
+++ b/docs/installation/installation.md
@@ -1,3 +1,5 @@
+([绠�浣撲腑鏂嘳(./installation_zh.md)|English)
+
 <p align="left">
     <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-brightgreen.svg"></a>
     <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
@@ -13,7 +15,7 @@
 wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
 sh Miniconda3-latest-Linux-x86_64.sh
 source ~/.bashrc
-conda create -n funasr python=3.7
+conda create -n funasr python=3.8
 conda activate funasr
 ```
 #### Mac
@@ -60,7 +62,7 @@
 ```shell
 pip3 install -U modelscope
 # For the users in China, you could install with the command:
-# pip3 install -U modelscope -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html -i https://mirror.sjtu.edu.cn/pypi/web/simple
+# pip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple
 ```
 
 ### FQA
diff --git a/docs/installation/installation_zh.md b/docs/installation/installation_zh.md
new file mode 100755
index 0000000..f663148
--- /dev/null
+++ b/docs/installation/installation_zh.md
@@ -0,0 +1,75 @@
+(绠�浣撲腑鏂噟[English](./installation.md))
+
+<p align="left">
+    <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-brightgreen.svg"></a>
+    <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
+    <a href=""><img src="https://img.shields.io/badge/Pytorch-%3E%3D1.11-blue"></a>
+</p>
+
+## 瀹夎
+
+### 瀹夎Conda锛堝彲閫夛級锛�
+
+#### Linux
+```sh
+wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
+sh Miniconda3-latest-Linux-x86_64.sh
+source ~/.bashrc
+conda create -n funasr python=3.8
+conda activate funasr
+```
+#### Mac
+```sh
+wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
+# For M1 chip
+# wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
+sh Miniconda3-latest-MacOSX*
+source ~/.zashrc
+conda create -n funasr python=3.8
+conda activate funasr
+```
+#### Windows
+Ref to [docs](https://docs.conda.io/en/latest/miniconda.html#windows-installers)
+
+### 瀹夎Pytorch锛堢増鏈� >= 1.11.0锛夛細
+
+```sh
+pip3 install torch torchaudio
+```
+濡傛灉鎮ㄧ殑鐜涓瓨鍦–UDAs锛屽垯搴斿畨瑁呬笌CUDA鍖归厤鐗堟湰鐨刾ytorch锛屽尮閰嶅垪琛ㄥ彲鍦ㄦ枃妗d腑鎵惧埌锛圼鏂囨。](https://pytorch.org/get-started/previous-versions/)锛夈��
+### 瀹夎funasr
+
+#### 浠巔ip瀹夎
+
+```shell
+pip3 install -U funasr
+# 瀵逛簬涓浗澶ч檰鐢ㄦ埛锛屽彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繘琛屽畨瑁咃細
+# pip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple
+```
+
+#### 鎴栬�呬粠婧愪唬鐮佸畨瑁�
+
+``` sh
+git clone https://github.com/alibaba/FunASR.git && cd FunASR
+pip3 install -e ./
+# 瀵逛簬涓浗澶ч檰鐢ㄦ埛锛屽彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繘琛屽畨瑁咃細
+# pip3 install -e ./ -i https://mirror.sjtu.edu.cn/pypi/web/simple
+```
+
+### 瀹夎modelscope锛堝彲閫夛級
+
+濡傛灉鎮ㄦ兂瑕佷娇鐢∕odelScope涓殑棰勮缁冩ā鍨嬶紝鍒欏簲瀹夎modelscope:
+
+```shell
+pip3 install -U modelscope
+# 瀵逛簬涓浗澶ч檰鐢ㄦ埛锛屽彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繘琛屽畨瑁咃細
+# pip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple
+```
+
+### 甯歌闂瑙g瓟
+- 鍦∕AC M1鑺墖涓婂畨瑁呮椂锛屽彲鑳戒細鍑虹幇浠ヤ笅閿欒锛�
+- - _cffi_backend.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
+    ```shell
+    pip uninstall cffi pycparser
+    ARCHFLAGS="-arch arm64" pip install cffi pycparser --compile --no-cache-dir
+    ```
diff --git a/docs/modelscope_pipeline/quick_start.md b/docs/modelscope_pipeline/quick_start.md
index 7e35e91..2b9219b 100644
--- a/docs/modelscope_pipeline/quick_start.md
+++ b/docs/modelscope_pipeline/quick_start.md
@@ -1,3 +1,5 @@
+([绠�浣撲腑鏂嘳(./quick_start_zh.md)|English)
+
 # Quick Start
 
 > **Note**: 
@@ -221,5 +223,4 @@
 If you want finetune with multi-GPUs, you could:
 ```shell
 CUDA_VISIBLE_DEVICES=1,2 python -m torch.distributed.launch --nproc_per_node 2 finetune.py > log.txt 2>&1
-```
-
+```
\ No newline at end of file
diff --git a/docs/modelscope_pipeline/quick_start_zh.md b/docs/modelscope_pipeline/quick_start_zh.md
new file mode 100644
index 0000000..91ad3c0
--- /dev/null
+++ b/docs/modelscope_pipeline/quick_start_zh.md
@@ -0,0 +1,227 @@
+(绠�浣撲腑鏂噟[English](./quick_start.md))
+
+# 蹇�熶娇鐢�
+
+> **娉ㄦ剰**: 
+> modelscope pipeline鏀寔model zoo涓殑鎵�鏈夋ā鍨嬭繘琛屾帹鐞嗗拰寰皟銆傝繖閲屾垜浠互typic妯″瀷涓轰緥鏉ユ紨绀虹敤娉曘��
+
+
+## 浣跨敤pipeline杩涜鎺ㄧ悊
+
+### 璇煶璇嗗埆
+#### Paraformer妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+
+inference_pipeline = pipeline(
+    task=Tasks.auto_speech_recognition,
+    model='damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch',
+)
+
+rec_result = inference_pipeline(audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav')
+print(rec_result)
+# {'text': '娆㈣繋澶у鏉ヤ綋楠岃揪鎽╅櫌鎺ㄥ嚭鐨勮闊宠瘑鍒ā鍨�'}
+```
+
+### 璇煶绔偣妫�娴�
+#### FSMN-VAD妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+from modelscope.utils.logger import get_logger
+import logging
+logger = get_logger(log_level=logging.CRITICAL)
+logger.setLevel(logging.CRITICAL)
+
+inference_pipeline = pipeline(
+    task=Tasks.voice_activity_detection,
+    model='damo/speech_fsmn_vad_zh-cn-16k-common-pytorch',
+    )
+
+segments_result = inference_pipeline(audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav')
+print(segments_result)
+# {'text': [[70, 2340], [2620, 6200], [6480, 23670], [23950, 26250], [26780, 28990], [29950, 31430], [31750, 37600], [38210, 46900], [47310, 49630], [49910, 56460], [56740, 59540], [59820, 70450]]}
+```
+
+### 鏍囩偣鎭㈠
+#### CT_Transformer妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+
+inference_pipeline = pipeline(
+    task=Tasks.punctuation,
+    model='damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch',
+    )
+
+rec_result = inference_pipeline(text_in='鎴戜滑閮芥槸鏈ㄥご浜轰笉浼氳璇濅笉浼氬姩')
+print(rec_result)
+# {'text': '鎴戜滑閮芥槸鏈ㄥご浜猴紝涓嶄細璁茶瘽锛屼笉浼氬姩銆�'}
+```
+
+### 鏃堕棿鎴抽娴�
+#### TP-Aligner妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+
+inference_pipeline = pipeline(
+    task=Tasks.speech_timestamp,
+    model='damo/speech_timestamp_prediction-v1-16k-offline',)
+
+rec_result = inference_pipeline(
+    audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_timestamps.wav',
+    text_in='涓� 涓� 涓� 澶� 骞� 娲� 鍥� 瀹� 涓� 浠� 涔� 璺� 鍒� 瑗� 澶� 骞� 娲� 鏉� 浜� 鍛�',)
+print(rec_result)
+# {'text': '<sil> 0.000 0.380;涓� 0.380 0.560;涓� 0.560 0.800;涓� 0.800 0.980;澶� 0.980 1.140;骞� 1.140 1.260;娲� 1.260 1.440;鍥� 1.440 1.680;瀹� 1.680 1.920;<sil> 1.920 2.040;涓� 2.040 2.200;浠� 2.200 2.320;涔� 2.320 2.500;璺� 2.500 2.680;鍒� 2.680 2.860;瑗� 2.860 3.040;澶� 3.040 3.200;骞� 3.200 3.380;娲� 3.380 3.500;鏉� 3.500 3.640;浜� 3.640 3.800;鍛� 3.800 4.150;<sil> 4.150 4.440;', 'timestamp': [[380, 560], [560, 800], [800, 980], [980, 1140], [1140, 1260], [1260, 1440], [1440, 1680], [1680, 1920], [2040, 2200], [2200, 2320], [2320, 2500], [2500, 2680], [2680, 2860], [2860, 3040], [3040, 3200], [3200, 3380], [3380, 3500], [3500, 3640], [3640, 3800], [3800, 4150]]}
+```
+
+### 璇磋瘽浜虹‘璁�
+#### X-vector妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+import numpy as np
+
+inference_sv_pipline = pipeline(
+    task=Tasks.speaker_verification,
+    model='damo/speech_xvector_sv-zh-cn-cnceleb-16k-spk3465-pytorch'
+)
+
+# embedding extract
+spk_embedding = inference_sv_pipline(audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav')["spk_embedding"]
+
+# speaker verification
+rec_result = inference_sv_pipline(audio_in=('https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav','https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav'))
+print(rec_result["scores"][0])
+# 0.8540499500025098
+```
+
+### 璇磋瘽浜烘棩蹇�
+#### SOND妯″瀷
+```python
+from modelscope.pipelines import pipeline
+from modelscope.utils.constant import Tasks
+
+inference_diar_pipline = pipeline(
+    mode="sond_demo",
+    num_workers=0,
+    task=Tasks.speaker_diarization,
+    diar_model_config="sond.yaml",
+    model='damo/speech_diarization_sond-en-us-callhome-8k-n16k4-pytorch',
+    model_revision="v1.0.3",
+    sv_model="damo/speech_xvector_sv-en-us-callhome-8k-spk6135-pytorch",
+    sv_model_revision="v1.0.0",
+)
+
+audio_list=[
+    "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_data/record.wav",
+    "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_data/spk_A.wav",
+    "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_data/spk_B.wav",
+    "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_data/spk_B1.wav"
+]
+
+results = inference_diar_pipline(audio_in=audio_list)
+print(results)
+# {'text': 'spk1 [(0.8, 1.84), (2.8, 6.16), (7.04, 10.64), (12.08, 12.8), (14.24, 15.6)]\nspk2 [(0.0, 1.12), (1.68, 3.2), (4.48, 7.12), (8.48, 9.04), (10.56, 14.48), (15.44, 16.0)]'}
+```
+
+### 甯歌闂
+#### 浣跨敤pipeline杩涜鎺ㄧ悊锛屽浣曞湪CPU涓嶨PU杩涜鍒囨崲
+
+The pipeline defaults to decoding with GPU (`ngpu=1`) when GPU is available. If you want to switch to CPU, you could set `ngpu=0`
+```python
+inference_pipeline = pipeline(
+    task=Tasks.auto_speech_recognition,
+    model='damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch',
+    ngpu=0,
+)
+```
+
+#### 濡備綍浠庢湰鍦版ā鍨嬭繘琛屾帹鐞嗭紙涓嶈仈缃戜娇鐢級
+浣跨敤modelscope-sdk灏嗘ā鍨嬩笅杞藉埌鏈湴
+
+```python
+from modelscope.hub.snapshot_download import snapshot_download
+
+local_dir_root = "./models_from_modelscope"
+model_dir = snapshot_download('damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch', cache_dir=local_dir_root)
+```
+
+鎴栬�呬娇鐢╣it灏嗘ā鍨嬩笅杞藉埌鏈湴
+```shell
+git lfs install
+# git clone https://www.modelscope.cn/<namespace>/<model-name>.git
+git clone https://www.modelscope.cn/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch.git
+```
+
+浠庝笅杞界殑鏈湴妯″瀷杩涜鎺ㄧ悊锛堝彲浠ヤ笉鑱旂綉浣跨敤锛�
+```python
+local_dir_root = "./models_from_modelscope/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
+inference_pipeline = pipeline(
+    task=Tasks.auto_speech_recognition,
+    model=local_dir_root,
+)
+```
+
+## 浣跨敤pipeline杩涜寰皟
+### 璇煶璇嗗埆
+#### Paraformer妯″瀷
+
+finetune.py
+```python
+import os
+from modelscope.metainfo import Trainers
+from modelscope.trainers import build_trainer
+from modelscope.msdatasets.audio.asr_dataset import ASRDataset
+
+def modelscope_finetune(params):
+    if not os.path.exists(params.output_dir):
+        os.makedirs(params.output_dir, exist_ok=True)
+    # dataset split ["train", "validation"]
+    ds_dict = ASRDataset.load(params.data_path, namespace='speech_asr')
+    kwargs = dict(
+        model=params.model,
+        data_dir=ds_dict,
+        dataset_type=params.dataset_type,
+        work_dir=params.output_dir,
+        batch_bins=params.batch_bins,
+        max_epoch=params.max_epoch,
+        lr=params.lr)
+    trainer = build_trainer(Trainers.speech_asr_trainer, default_args=kwargs)
+    trainer.train()
+
+
+if __name__ == '__main__':
+    from funasr.utils.modelscope_param import modelscope_args
+    params = modelscope_args(model="damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch")
+    params.output_dir = "./checkpoint"                      # 妯″瀷淇濆瓨璺緞
+    params.data_path = "speech_asr_aishell1_trainsets"      # 鏁版嵁璺緞锛屽彲浠ヤ负modelscope涓凡涓婁紶鏁版嵁锛屼篃鍙互鏄湰鍦版暟鎹�
+    params.dataset_type = "small"                           # 灏忔暟鎹噺璁剧疆small锛岃嫢鏁版嵁閲忓ぇ浜�1000灏忔椂锛岃浣跨敤large
+    params.batch_bins = 2000                                # batch size锛屽鏋渄ataset_type="small"锛宐atch_bins鍗曚綅涓篺bank鐗瑰緛甯ф暟锛屽鏋渄ataset_type="large"锛宐atch_bins鍗曚綅涓烘绉掞紝
+    params.max_epoch = 50                                   # 鏈�澶ц缁冭疆鏁�
+    params.lr = 0.00005                                     # 璁剧疆瀛︿範鐜�
+    
+    modelscope_finetune(params)
+```
+
+```shell
+python finetune.py &> log.txt &
+```
+tail log.txt
+```
+[bach-gpu011024008134] 2023-04-23 18:59:13,976 (e2e_asr_paraformer:467) INFO: enable sampler in paraformer, sampling_ratio: 0.75
+[bach-gpu011024008134] 2023-04-23 18:59:48,924 (trainer:777) INFO: 2epoch:train:1-50batch:50num_updates: iter_time=0.008, forward_time=0.302, loss_att=0.186, acc=0.942, loss_pre=0.005, loss=0.192, backward_time=0.231, optim_step_time=0.117, optim0_lr0=7.484e-06, train_time=0.753
+[bach-gpu011024008134] 2023-04-23 19:00:23,869 (trainer:777) INFO: 2epoch:train:51-100batch:100num_updates: iter_time=1.152e-04, forward_time=0.275, loss_att=0.184, acc=0.945, loss_pre=0.005, loss=0.189, backward_time=0.234, optim_step_time=0.117, optim0_lr0=7.567e-06, train_time=0.699
+[bach-gpu011024008134] 2023-04-23 19:00:58,463 (trainer:777) INFO: 2epoch:train:101-150batch:150num_updates: iter_time=1.123e-04, forward_time=0.271, loss_att=0.204, acc=0.942, loss_pre=0.005, loss=0.210, backward_time=0.231, optim_step_time=0.116, optim0_lr0=7.651e-06, train_time=0.692
+```
+
+### 甯歌闂
+### 澶欸PU璁粌
+
+鍙互浣跨敤涓嬮潰鐨勬寚浠よ繘琛屽GPU璁粌
+```shell
+CUDA_VISIBLE_DEVICES=1,2 python -m torch.distributed.launch --nproc_per_node 2 finetune.py > log.txt 2>&1
+```
+

--
Gitblit v1.9.1