ແຕ່ງເພງດ້ວຍ AI
ໂນດເພງກໍແມ່ນ token: ທາຍໂນດຖັດໄປຄືກັບທາຍຄຳຖັດໄປ.
ເພງມີທັງ pitch ແລະ duration ຈຶ່ງໃຊ້ Transformer ທີ່ມີ 2 ສາຍ input/output. ເພງຫຼາຍສຽງ (polyphonic) ຕ້ອງເລືອກວິທີ tokenize: grid (ແບ່ງເວລາເປັນຊ່ອງ) ຫຼື event (ລຳດັບຄຳສັ່ງ). MuseGAN ໃຊ້ convolution ສ້າງເພງຫຼາຍ track ຄືກັບສ້າງຮູບ.
ໂຄດຕົວຢ່າງໃຊ້ autoregressive model ທີ່ງ່າຍທີ່ສຸດ (bigram) ກັບ token ແບບ ໂນດ:ຄວາມຍາວ ແລະ ແຕ່ງເພງສັ້ນ 3 ທ່ອນ.
| ວິທີ | ແນວຄິດ |
|---|---|
| Transformer (note + duration) | 2 embedding ລວມກັນ, ທາຍທັງໂນດ ແລະ ຄວາມຍາວຖັດໄປ |
| Grid tokenization | ແບ່ງເວລາເປັນຊ່ອງເທົ່າກັນ ແລ້ວອ່ານທຸກສຽງເປັນສາຍດຽວ |
| Event tokenization | ຂຽນເປັນຄຳສັ່ງ: ກົດໂນດ, ລໍຖ້າ, ປ່ອຍໂນດ |
| MuseGAN | ເບິ່ງເພງເປັນຮູບ (piano roll) ແລ້ວໃຊ້ GAN |
ສິ່ງທີ່ຄວນຈື່
- ຜົນຂອງ AI ແຕ່ງເພງ ຂຶ້ນກັບວິທີ tokenize ຫຼາຍ
- Model ຮຽນ key ແລະ scale ໄດ້ເອງ ພຽງແຕ່ຈາກການທາຍໂນດຖັດໄປ
import numpy as np
rng = np.random.default_rng(1)
# A tiny corpus of melodies as (note, duration) tokens
songs = [
"C4:1 E4:1 G4:1 E4:1 C4:2", "C4:1 D4:1 E4:1 G4:1 E4:2",
"E4:1 G4:1 A4:1 G4:1 E4:2", "G4:1 E4:1 D4:1 C4:1 C4:2",
]
tokens = [s.split() + ["END"] for s in songs]
vocab = sorted({t for song in tokens for t in song} | {"START"})
ix = {t: i for i, t in enumerate(vocab)}
# Bigram model p(next | current): the simplest autoregressive music model
counts = np.zeros((len(vocab), len(vocab)))
for song in tokens:
for a, b in zip(["START"] + song, song):
counts[ix[a], ix[b]] += 1
probs = counts / np.maximum(counts.sum(1, keepdims=True), 1)
def compose(max_len=10):
cur, out = "START", []
for _ in range(max_len):
cur = vocab[rng.choice(len(vocab), p=probs[ix[cur]])]
if cur == "END": break
out.append(cur)
return " ".join(out)
for i in range(3):
print(f"melody {i + 1}: {compose()}")
ຜົນລັບ
melody 1: E4:1 G4:1 A4:1 G4:1 E4:1 G4:1 E4:2 melody 2: E4:1 C4:2 melody 3: E4:1 D4:1 E4:1 D4:1 C4:1 C4:2
- #GenerativeAI
- #DeepLearning
- #PythonສຳລັບຄົນLaos
- #AI
- #ບອກຕໍ່ຄວາມຮູ້