synthesis.pyではDataset, DataLoaderが使われず、またオノマトペを音素文字列として自由に与えることができる点に、inference.pyとの違いがある。例えば、オノマトペが"ビイイイイ"(/b i i i i i/)なら "b i i i i i" のように与えることができる、といった具合である。手元で色々とオノマトペを変えながら環境音合成を試す際にはsynthesis.pyのほうが便利である。
Installing collected packages: PyYAML, chatterbot-corpus
Attempting uninstall: PyYAML
Found existing installation: PyYAML 5.3.1
Uninstalling PyYAML-5.3.1:
Successfully uninstalled PyYAML-5.3.1
Running setup.py install for PyYAML ... done
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
chatterbot 1.1.0a7 requires pyyaml<5.4,>=5.3, but you have pyyaml 3.13 which is incompatible.
Successfully installed PyYAML-3.13 chatterbot-corpus-1.2.0
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('test')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.japanese")
response = chatbot.get_response("こんにちは")
print(response)
これを適当な名前で保存する(test_chat.pyとか)。
そして実行する。
python3 test_chat.py
すると以下の実行結果が得られる。
Training ai.yml: [####################] 100%
Training botprofile.yml: [####################] 100%
Training computers.yml: [####################] 100%
Training conversations.yml: [####################] 100%
Training emotion.yml: [####################] 100%
Training food.yml: [####################] 100%
Training gossip.yml: [####################] 100%
Training greetings.yml: [####################] 100%
Training health.yml: [####################] 100%
Training history.yml: [####################] 100%
Training humor.yml: [####################] 100%
Training literature.yml: [####################] 100%
Training money.yml: [####################] 100%
Training movies.yml: [####################] 100%
Training politics.yml: [####################] 100%
Training psychology.yml: [####################] 100%
Training science.yml: [####################] 100%
Training sports.yml: [####################] 100%
Training trivia.yml: [####################] 100%
お元気ですか?
from torch.optim.lr_scheduler import _LRScheduler
classTransformerLR(_LRScheduler):
"""TransformerLR class for adjustment of learning rate. The scheduling is based on the method proposed in 'Attention is All You Need'. """def__init__(self, optimizer, warmup_epochs=1000, last_epoch=-1, verbose=False):
"""Initialize class."""
self.warmup_epochs = warmup_epochs
self.normalize = self.warmup_epochs**0.5super().__init__(optimizer, last_epoch, verbose)
defget_lr(self):
"""Return adjusted learning rate."""
step = self.last_epoch + 1
scale = self.normalize * min(step**-0.5, step * self.warmup_epochs**-1.5)
return [base_lr * scale for base_lr in self.base_lrs]
まず第一に、RWCP 実環境音声・音響データベース (Real World Computing Partnership-Sound Scene Database; RWCP-SSD) を入手すること。これがないと始まらない。以下のページを参考に。オンライン配布にも対応しており、アカデミア関係者ならば入手は容易である。
ポンッ,p o N q,/path/to/your/dataset/nospeech/drysrc/a1/cherry1/16khz/005.wav,cherry1
トッ,t o q,/path/to/your/dataset/nospeech/drysrc/a1/cherry1/16khz/005.wav,cherry1
コンッ,k o N q,/path/to/your/dataset/nospeech/drysrc/a1/cherry1/16khz/005.wav,cherry1
トッ,t o q,/path/to/your/dataset/nospeech/drysrc/a1/cherry1/16khz/005.wav,cherry1
...
# -*- coding: utf-8 -*-from time import sleep
from progressbar import progressbar as prg
for i in prg(range(10), prefix="A demonstration", suffix="\n"):
sleep(0.1)
print(i)
ターミナル出力はこんな感じ(アニメーションを用意したい!)。
A demonstration 0% (0 of 10) | | Elapsed Time: 0:00:00 ETA: --:--:--
0
A demonstration 10% (1 of 10) |####### | Elapsed Time: 0:00:00 ETA: 0:00:00
1
A demonstration 20% (2 of 10) |############### | Elapsed Time: 0:00:00 ETA: 0:00:00
2
A demonstration 30% (3 of 10) |###################### | Elapsed Time: 0:00:00 ETA: 0:00:00
3
A demonstration 40% (4 of 10) |############################## | Elapsed Time: 0:00:00 ETA: 0:00:00
4
A demonstration 50% (5 of 10) |##################################### | Elapsed Time: 0:00:00 ETA: 0:00:00
5
A demonstration 60% (6 of 10) |############################################# | Elapsed Time: 0:00:00 ETA: 0:00:00
6
A demonstration 70% (7 of 10) |#################################################### | Elapsed Time: 0:00:00 ETA: 0:00:00
7
A demonstration 80% (8 of 10) |############################################################ | Elapsed Time: 0:00:00 ETA: 0:00:00
8
A demonstration 90% (9 of 10) |################################################################### | Elapsed Time: 0:00:00 ETA: 0:00:00
9
A demonstration100% (10 of 10) |##########################################################################| Elapsed Time: 0:00:01 Time: 0:00:01
# -*- coding: utf-8 -*-from time import sleep
from progressbar import progressbar as prg
for i in prg(range(10), prefix="A demonstration", suffix="\n", redirect_stdout=True):
sleep(0.1)
print(i)
その際、log.txtの中身は
A demonstration 0% (0 of 10) | | Elapsed Time: 0:00:00 ETA: --:--:--
0
A demonstration 0% (0 of 10) | | Elapsed Time: 0:00:00 ETA: --:--:--
1
A demonstration 10% (1 of 10) |####### | Elapsed Time: 0:00:00 ETA: 0:00:01
2
A demonstration 20% (2 of 10) |############### | Elapsed Time: 0:00:00 ETA: 0:00:01
3
A demonstration 30% (3 of 10) |###################### | Elapsed Time: 0:00:00 ETA: 0:00:00
4
A demonstration 40% (4 of 10) |############################## | Elapsed Time: 0:00:00 ETA: 0:00:00
5
A demonstration 50% (5 of 10) |##################################### | Elapsed Time: 0:00:00 ETA: 0:00:00
6
A demonstration 60% (6 of 10) |############################################# | Elapsed Time: 0:00:00 ETA: 0:00:00
7
A demonstration 70% (7 of 10) |#################################################### | Elapsed Time: 0:00:00 ETA: 0:00:00
8
A demonstration 80% (8 of 10) |############################################################ | Elapsed Time: 0:00:00 ETA: 0:00:00
9
A demonstration 90% (9 of 10) |################################################################### | Elapsed Time: 0:00:01 ETA: 0:00:00
A demonstration100% (10 of 10) |##########################################################################| Elapsed Time: 0:00:01 Time: 0:00:01