File size: 4,558 Bytes
650ef1a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "DP_Inference.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "bsvxO3kfo_sr"
},
"source": [
"pip install deep-phonemizer"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "XRTPugZ0pL-b"
},
"source": [
"from dp.phonemizer import Phonemizer\n",
"\n",
"!wget https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt\n",
"\n",
"phonemizer = Phonemizer.from_checkpoint('en_us_cmudict_ipa_forward.pt')"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"id": "ei9oN93rpilk",
"outputId": "1461e27d-ba72-4249-9ecf-f98a9563dee0"
},
"source": [
"phonemizer('Phonemizing an English text is imposimpable!', lang='en_us')"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'fɑːnəmaɪzɪŋ æn ɪŋglɪʃ tɛkst aɪz ɪmpəzɪmpəbəl!'"
]
},
"metadata": {
"tags": []
},
"execution_count": 3
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Cq8zgZOMpk5T",
"outputId": "ceb1269b-619d-402a-c661-f5be5f4d2154"
},
"source": [
"# Phonemize a list of texts and pull out model predictions with confidence scores\n",
"result = phonemizer.phonemise_list(['Phonemizing an US-English text is imposimpable!', 'Holymoly.'], lang='en_us')\n",
"\n",
"for word, pred in result.predictions.items():\n",
" print(f'{word} {pred.phonemes} {pred.confidence}')"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Phonemizing fɑːnəmaɪzɪŋ 0.9998687552490106\n",
"Holymoly hɑːliːmɑːli 0.6092846695646951\n",
"imposimpable ɪmpəzɪmpəbəl 0.9988885450352498\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ylKahJLhpltv",
"outputId": "93dfd4b0-58f9-4c30-f105-b9f8dec00a9f"
},
"source": [
"# Print confidence per phoneme\n",
"result = phonemizer.phonemise_list(['Otorhinolaryngologist'], lang='en_us')\n",
"pred = result.predictions['Otorhinolaryngologist']\n",
"\n",
"print(f'{pred.phonemes} {pred.confidence}\\n')\n",
"\n",
"for c, prob in zip(pred.phoneme_tokens, pred.token_probs):\n",
" print(f'{c} {prob}')"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"oʊtɔrhɪnɑːlɛrɪŋgoʊlgɪst 0.6062305000504705\n",
"\n",
"<en_us> 1.0\n",
"o 1.0\n",
"ʊ 0.999997615814209\n",
"t 1.0\n",
"ɔ 0.8052271008491516\n",
"r 0.9994328618049622\n",
"h 1.0\n",
"ɪ 0.9999969005584717\n",
"n 1.0\n",
"ɑ 0.9980535507202148\n",
"ː 0.9757038354873657\n",
"l 1.0\n",
"ɛ 0.7834091186523438\n",
"r 0.9998308420181274\n",
"ɪ 0.9999746084213257\n",
"ŋ 0.999996542930603\n",
"g 0.9999998807907104\n",
"o 0.999997615814209\n",
"ʊ 0.9968417882919312\n",
"l 1.0\n",
"g 0.9992079138755798\n",
"ɪ 0.9950146079063416\n",
"s 0.9965135455131531\n",
"t 1.0\n",
"<end> 1.0\n"
],
"name": "stdout"
}
]
}
]
} |