Search⌘ K
AI Features

إنشاء تضمينات لملفات الصوت وبيانات الأغاني الوصفية

تعلم كيفية إنشاء تضمينات لبيانات تعريف الأغاني والصوت.

تضمينات البيانات الوصفية باستخدام نموذج تضمين BERT

لاستخدام BERT لإنشاء تضمين البيانات الوصفية، نحتاج إلى تحويل معلومات البيانات الوصفية الجدولية (السمات والقيم) للأغنية إلى سلسلة نصية، والتي نسميهاtextual_description من الأغنية. على سبيل المثال:

"تتمتع أغنية Infinity Edge بقابلية رقص تبلغ 0.528، وطاقة تبلغ 0.847، ومستوى صوت يبلغ -4.741، ووضوح كلامي يبلغ 0.0307، وصوتية تبلغ 0.00674، وطابع موسيقي يبلغ 0.814، وحيوية تبلغ 0.12، وقيمة تبلغ 0.389، وإيقاع يبلغ 143.997."

للقيام بذلك، نقرأ ملف CSV الذي يحتوي على بيانات وصفية عن الأغاني، وننشئ نصًا وصفيًا لكل أغنية باستخدام سماتها وقيمها. نضيف هذا النص إلى DataFrame، ثم نحفظ DataFrame المُحدَّث مرة أخرى في ملف CSV.

Python 3.10.4
import pandas as pd
metadata_file_path="/content/drive/MyDrive/vector-databases-course/music-recommendation-system/dataset/reduced_80_fer2013_music_dataset_with_youtube_URLS.csv"
# Loading metadata into DataFrame
metadata_df = pd.read_csv(metadata_file_path)
# Extracting relevant numeric attribute and creating a textual description using them
metadata_df['textual_description'] = metadata_df.apply(
lambda row: f"The song {row['song_name']} has a danceability of {row['danceability']}, "
f"energy of {row['energy']}, "
f"loudness of {row['loudness']}, "
f"speechiness of {row['speechiness']}, "
f"acousticness of {row['acousticness']}, "
f"instrumentalness of {row['instrumentalness']}, "
f"liveness of {row['liveness']}, "
f"valence of {row['valence']}, "
f"tempo of {row['tempo']}",
axis=1
)
# Saving the updated DataFrame with the textual descriptions for each song back to the CSV file
metadata_df.to_csv(metadata_file_path, index=False)
print("The 'textual_description' column has been added to the CSV file.")

الtextual_description تمت إضافة عمود إلى metadata_song.csv يظهر الملف في الرسم التوضيحي أدناه:

textual_description column added to the metadata_songs.csv file
textual_description column added to the metadata_songs.csv file

في الكود التالي، نُعرّفSPECIAL_TOKENS بالنسبة للخصائص الرقمية للأغاني التي سيتعامل معها نموذج BERT كخصائص خاصة، وليست نصوصًا عادية، نستبدل هذه الخصائص في الأوصاف النصية بالرموز الخاصة المقابلة. يساعد هذا النموذج على التمييز بين أسماء الخصائص والنصوص الأخرى، مما يحسن ...