File size: 4,541 Bytes
af1acfc | 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 | {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "abf300bb",
"metadata": {},
"outputs": [],
"source": [
"from stanza.utils.visualization.ner_visualization import visualize_strings\n",
"\n",
"en_strings = ['''Samuel Jackson, a Christian man from Utah, went to the JFK Airport for a flight to New York.\n",
" He was thinking of attending the US Open, his favorite tennis tournament besides Wimbledon.\n",
" That would be a dream trip, certainly not possible since it is $5000 attendance and 5000 miles away.\n",
" On the way there, he watched the Super Bowl for 2 hours and read War and Piece by Tolstoy for 1 hour.\n",
" In New York, he crossed the Brooklyn Bridge and listened to the 5th symphony of Beethoven as well as\n",
" \"All I want for Christmas is You\" by Mariah Carey.''', \n",
" \"Barack Obama was born in Hawaii. He was elected President of the United States in 2008\"]\n",
" \n",
"visualize_strings(en_strings, \"en\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5670921a",
"metadata": {},
"outputs": [],
"source": [
"from stanza.utils.visualization.ner_visualization import visualize_strings\n",
"\n",
"zh_strings = ['''来自犹他州的基督徒塞缪尔杰克逊前往肯尼迪机场搭乘航班飞往纽约。\n",
" 他正在考虑参加美国公开赛,这是除了温布尔登之外他最喜欢的网球赛事。\n",
" 那将是一次梦想之旅,当然不可能,因为它的出勤费为 5000 美元,距离 5000 英里。\n",
" 在去的路上,他看了 2 个小时的超级碗比赛,看了 1 个小时的托尔斯泰的《战争与碎片》。\n",
" 在纽约,他穿过布鲁克林大桥,聆听了贝多芬的第五交响曲以及 玛丽亚凯莉的“圣诞节我想要的就是你”。''',\n",
" \"我觉得罗家费德勒住在加州, 在美国里面。\"]\n",
"visualize_strings(zh_strings, \"zh\", colors={\"PERSON\": \"yellow\", \"DATE\": \"red\", \"GPE\": \"blue\"})\n",
"visualize_strings(zh_strings, \"zh\", select=['PERSON', 'DATE'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8d96072",
"metadata": {},
"outputs": [],
"source": [
"from stanza.utils.visualization.ner_visualization import visualize_strings\n",
"\n",
"ar_strings = [\".أعيش في سان فرانسيسكو ، كاليفورنيا. اسمي أليكس وأنا ألتحق بجامعة ستانفورد. أنا أدرس علوم الكمبيوتر وأستاذي هو كريس مانينغ\"\n",
" , \"اسمي أليكس ، أنا من الولايات المتحدة.\", \n",
" '''صامويل جاكسون ، رجل مسيحي من ولاية يوتا ، ذهب إلى مطار جون كنيدي في رحلة إلى نيويورك. كان يفكر في حضور بطولة الولايات المتحدة المفتوحة للتنس ، بطولة التنس المفضلة لديه إلى جانب بطولة ويمبلدون. ستكون هذه رحلة الأحلام ، وبالتأكيد ليست ممكنة لأنها تبلغ 5000 دولار للحضور و 5000 ميل. في الطريق إلى هناك ، شاهد Super Bowl لمدة ساعتين وقرأ War and Piece by Tolstoy لمدة ساعة واحدة. في نيويورك ، عبر جسر بروكلين واستمع إلى السيمفونية الخامسة لبيتهوفن وكذلك \"كل ما أريده في عيد الميلاد هو أنت\" لماريا كاري.''']\n",
"\n",
"visualize_strings(ar_strings, \"ar\", colors={\"PER\": \"pink\", \"LOC\": \"linear-gradient(90deg, #aa9cfc, #fc9ce7)\", \"ORG\": \"yellow\"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22489b27",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|