chrisjay commited on
Commit
6e75ca4
1 Parent(s): 458a341

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +5 -85
README.md CHANGED
@@ -43,96 +43,16 @@ import torchaudio
43
  from datasets import load_dataset
44
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
45
 
46
- #This will download the files from Layele's Github to the directory FonAudio
47
- if not os.path.isdir("./FonAudio"):
48
- !wget https://github.com/laleye/pyFongbe/archive/master/data.zip
49
- with zipfile.ZipFile("data.zip","r") as zip_ref:
50
- zip_ref.extractall("./FonAudio")
51
-
52
- with open('./FonAudio/pyFongbe-master/data/train.csv', newline='',encoding='UTF-8') as f:
53
- reader = csv.reader(f)
54
- data = list(reader)
55
- train_data = [data[i] for i in range(len(data)) if i!=0]
56
-
57
- with open('./FonAudio/pyFongbe-master/data/test.csv', newline='',encoding='UTF-8') as f:
58
- reader = csv.reader(f)
59
- data = list(reader)
60
- t_data = [data[i] for i in range(len(data)) if i!=0]
61
-
62
-
63
- #Get valid indices
64
- random.seed(42) #this seed was used specifically to compare
65
- # with Okwugbe model (https://arxiv.org/abs/2103.07762)
66
-
67
-
68
- v = 1500
69
- test_list = [i for i in range(len(t_data))]
70
- valid_indices = random.choices(test_list, k=v)
71
-
72
- test_data = [t_data[i] for i in range(len(t_data)) if i not in valid_indices]
73
- valid_data = [t_data[i] for i in range(len(t_data)) if i in valid_indices]
74
-
75
- #Final length of validation_dataset -> 1107
76
- #Final length of test_dataset -> 1061
77
-
78
- #Please note, the final validation size is is smaller than the
79
- #expected (1500) because we used random.choices which could contain duplicates.
80
-
81
- #Create JSON files
82
- def create_json_file(d):
83
- utterance = d[2]
84
- wav_path =d[0]
85
- wav_path = wav_path.replace("/home/frejus/Projects/Fongbe_ASR/pyFongbe","./FonAudio/pyFongbe-master")
86
- return {
87
- "path": wav_path,
88
- "sentence": utterance
89
- }
90
-
91
- train_json = [create_json_file(i) for i in train_data]
92
- test_json = [create_json_file(i) for i in test_data]
93
- valid_json = [create_json_file(i) for i in valid_data]
94
-
95
- #Save JSON files to your Google Drive folders
96
- #Make folder in GDrive to store files
97
- train_path = '/content/drive/MyDrive/fon_xlsr/train'
98
- test_path = '/content/drive/MyDrive/fon_xlsr/test'
99
- valid_path = '/content/drive/MyDrive/fon_xlsr/valid'
100
-
101
- if not os.path.isdir(train_path):
102
- print("Creating paths")
103
- os.makedirs(train_path)
104
- os.makedirs(test_path) #this is where we save the test files
105
- os.makedirs(valid_path)
106
-
107
-
108
- #for train
109
- for i, sample in enumerate(train_json):
110
- file_path = os.path.join(train_path,'train_fon_{}.json'.format(i))
111
- with open(file_path, 'w') as outfile:
112
- json.dump(sample, outfile)
113
-
114
- #for test
115
- for i, sample in enumerate(test_json):
116
- file_path = os.path.join(test_path,'test_fon_{}.json'.format(i))
117
- with open(file_path, 'w') as outfile:
118
- json.dump(sample, outfile)
119
-
120
- #for valid
121
- for i, sample in enumerate(valid_json):
122
- file_path = os.path.join(valid_path,'valid_fon_{}.json'.format(i))
123
- with open(file_path, 'w') as outfile:
124
- json.dump(sample, outfile)
125
-
126
 
127
  #Load test_dataset from saved files in folder
128
  from datasets import load_dataset, load_metric
129
 
130
  #for test
131
- for root, dirs, files in os.walk(test_path):
132
  test_dataset= load_dataset("json", data_files=[os.path.join(root,i) for i in files],split="train")
133
 
134
  #Remove unnecessary chars
135
- chars_to_ignore_regex =
136
  def remove_special_characters(batch):
137
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
138
  return batch
@@ -176,10 +96,10 @@ from datasets import load_dataset, load_metric
176
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
177
  import re
178
 
179
- for root, dirs, files in os.walk(test_path):
180
  test_dataset = load_dataset("json", data_files=[os.path.join(root,i) for i in files],split="train")
181
 
182
- chars_to_ignore_regex =
183
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
184
  return batch
185
 
@@ -187,7 +107,7 @@ test_dataset = test_dataset.map(remove_special_characters)
187
  wer = load_metric("wer")
188
 
189
  processor = Wav2Vec2Processor.from_pretrained("chrisjay/wav2vec2-large-xlsr-53-fon")
190
- model = Wav2Vec2ForCTC.from_pretrained("chrisjay/wav2vec2-large-xlsr-53-fon") #use checkpoint-12400 to get our WER test results
191
  model.to("cuda")
192
 
193
  # Preprocessing the datasets.
 
43
  from datasets import load_dataset
44
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  #Load test_dataset from saved files in folder
48
  from datasets import load_dataset, load_metric
49
 
50
  #for test
51
+ for root, dirs, files in os.walk(test/):
52
  test_dataset= load_dataset("json", data_files=[os.path.join(root,i) for i in files],split="train")
53
 
54
  #Remove unnecessary chars
55
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”]'
56
  def remove_special_characters(batch):
57
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
58
  return batch
 
96
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
97
  import re
98
 
99
+ for root, dirs, files in os.walk(test/):
100
  test_dataset = load_dataset("json", data_files=[os.path.join(root,i) for i in files],split="train")
101
 
102
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”]'
103
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
104
  return batch
105
 
 
107
  wer = load_metric("wer")
108
 
109
  processor = Wav2Vec2Processor.from_pretrained("chrisjay/wav2vec2-large-xlsr-53-fon")
110
+ model = Wav2Vec2ForCTC.from_pretrained("chrisjay/wav2vec2-large-xlsr-53-fon")
111
  model.to("cuda")
112
 
113
  # Preprocessing the datasets.