\r\n
\r\n

\r\n

The result to listen to

\r\n

Here are some songs that attracted my attention:

\r\n\r\n

If you find more interesting examples, just let me know or simply put them in the comments bellow. I do realize that my music taste can be questionable ;)

\r\n

Special thanks

\r\n

Since all my calculations were performed on the Hadoop cluster that belongs to ICM UW, I would like to give big thanks to the ICM’s staff for the possibility to use the cluster.

","bodyAsHTML":"

Recently I have found an interesting dataset, called Million Song Dataset (MSD) which contains detailed acoustic and contextual data about a million songs. For each song we can find information like title, hotness, tempo, duration, danceability, loudness as well as artist’s name, popularity, localization (latitude and longitude pair) and many others. There are no music files included here, but the links to MP3 songs’ previews at 7digital.com can be easily constructed from the data. \r\n

The dataset consists of 339 tab-separated text files. Each file contains about 3000 songs and each song is represented as one separate line of text. The dataset is publicly available and you can find it at Infochimps or Amazon S3. Since the total size of this data sums up to around 218 GB, processing it using one machine may take very long time.

\r\n

Definitely, much more interesting and efficient approach is to use multiple machines and process the songs in parallel fashion by taking advantage of open-source tools from Apache Hadoop Ecosystem (e.g. Apache Pig). If you have some own machines, you can simply use CDH (Cloudera’s Distribution including Apache Hadoop) which includes the complete Apache Hadoop stack. CDH can be installed manually (quickly and easily by typing a couple of simple comands) or even automatically using Cloudera Manager Free Edition. Both CDH and Cloudera Manager are freely downloadable from the Cloudera website. Alternatively, you may rent some machines from Amazon with Hadoop already installed and process the data using Amazon’s Elastic MapReduce (here is a cool description writen by Paul Lemere how to use it and pay as low as $1, and here is my presentation about Elastic MapReduce given at the 2nd meeting of Warsaw Hadoop User Group).

\r\n

Problem definition

\r\n

I came up with the idea to process this dataset to find “exotic” (but still popular) songs. By an exotic songs, I simply mean a song which is recorded by an artist who lives in some foreign country, far away from other artists. The general goal is to discover a couple of fancy and folk songs which are associated with the culture of some country. A funny example could be the song “Koko Koko Euro Spoko” by Jarzębina which was chosen by Poles to be the official song of Polish national football team during UEFA EURO 2012 ;)

\r\n


\r\n

\r\n

Apache Pig

\r\n

I have used Apache Pig to achieve this goal. Apache Pig is a convenient tool created at Yahoo! to analyze large datasets easily and efficiently. Apache Pig provides a high level and easy to learn, understand and maintain data flow programming language, called PigLatin. PigLatin is quite similar to scripting languages, it supports many useful operations like filtering, sorting, aggregation, joining, splitting and provides several complex data types (tuples, bags and maps). An exemplary PigLatin script is 20x shorter than its equivalent in Java MapReduce and takes a programmer 16x less time to implement it (read more), at the same time being only slightly slower than Java MapReduce (see PigMix2 benchmark). Thanks to these advantages, Apache Pig is often used by many well-recognized companies and organizations e.g. Yahoo! (currently about 90% Hadoop jobs is written in PigLatin), Twitter, Nokia Ovi Maps, AOL, Mendeley, LinkedIn and ICM UW.

\r\n

PigLatin script

\r\n

To find such popular folk and local songs, I have implemented a simple PigLatin script (about 50 lines of PigLatin code). This script uses a bit naive, but quite effective idea and tries to search for “isolated” songs. An isolated song is simply a song where the average distance between its artist localization and any other artists is as low as possible (to be more precise, I should say that an isolated song is a song recorded by an isolated artist). This approach gives us much bigger probability to discover “ear-catching” songs from Congo, Mali, Poland and Vietnam than from the US or the UK.

\r\n

As mentioned, the dataset contains artists’ localization information in form of lat/long pairs and luckily there is a open-source library DataFu (created by LinkedIn) that provides e.g. PigLatin UDF to calculate distance between two lat/long pairs using the Haversine formula.

\r\n

Just in a few words. I read the input data and filter out unpopular songs or songs without lat/long localization (relation Filtered). Then I produce all pairs of different songs (relation Different) and calculate distance between their artists localization (relation Distanced). Next, for each song, I calculate the average distance between the song’s artist localization and all other songs’ artists localization (relation AvgDistanced). Now, I can limit my records to take only the most interesting results. Firstly, I want to have only the hottest song for a given location (relation Popular). Then I remain only a small number of songs with the lowest average distance (relation Limited) and finally store output results in the the format that will be useful for further visualization with GoogleMaps (relation Displable).

\r\n

Here is a source code:

SET default_parallel $parallel\r\nSET pig.tmpfilecompression true\r\nSET pig.tmpfilecompression.codec lzo\r\nSET pig.maxCombinedSplitSize 134217728\r\n \r\nREGISTER '/usr/lib/pig-0.10.0/contrib/datafu-0.0.4/dist/datafu-0.0.4.jar';\r\nDEFINE haversineMiles datafu.pig.geo.HaversineDistInMiles();\r\n \r\nSongs = LOAD '$input';\r\n--"Project early and often"\r\nProjected = FOREACH Songs GENERATE\r\n        (double) $6 AS artistLat, (double) $8 AS artistLong, $12 AS artistName,\r\n        (double) $43 AS songHotness, $51 AS songTitle, (int) $52 AS songPreview;\r\n \r\n--"Filter early and often"\r\nFiltered = FILTER Projected BY (songHotness >= $hotness) AND (artistLat IS NOT NULL) AND (artistLong IS NOT NULL);\r\n--"Copy useful fields from Popluar relation"\r\nFiltered2 = FOREACH Filtered GENERATE songPreview as song2Preview, artistLat AS artist2Lat, artistLong AS artist2Long;\r\n \r\n--"Produce all pairs of different songs and calculate distance between localizations of their artists"\r\nCrossed = CROSS Filtered, Filtered2;\r\nDifferent = FILTER Crossed BY songPreview != song2Preview;\r\nDistanced = FOREACH Different GENERATE artistLat..songPreview,\r\n        haversineMiles(artistLat, artistLong, artist2Lat, artist2Long) as distance;\r\n \r\n--"For each song, calculate average distance between its artists and all other artists"\r\nGrouped = GROUP Distanced BY artistLat..songPreview;\r\nAvgDistanced = FOREACH Grouped {\r\n        Distances = Distanced.distance;\r\n        GENERATE FLATTEN(group), AVG(Distances) AS distanceAvg;\r\n}\r\n \r\n--"Find the most popular song for a given location"\r\nLocationed = GROUP AvgDistanced BY (artistLat, artistLong);\r\nPopular = FOREACH Locationed {\r\n        OrderedSongs = ORDER AvgDistanced BY songHotness DESC;\r\n        TopSong = LIMIT OrderedSongs 1;\r\n        GENERATE FLATTEN(TopSong);\r\n}\r\n--"Find the most isolated songs which were recored by artists who live far away from other artists"\r\nOrdered = ORDER Popular BY distanceAvg DESC;\r\nLimited = LIMIT Ordered $topCount;\r\n \r\n--"Generate results in such a format that can be easily displayed by Google Maps (by copy & paste)"\r\nDisplayed = FOREACH Limited GENERATE\r\n        CONCAT('[', (chararray) artistLat), artistLong, songPreview,\r\n        CONCAT('"', CONCAT((chararray) songTitle, '"')),\r\n        CONCAT('"', CONCAT((chararray) artistName, '"')),\r\n        songHotness,\r\n        CONCAT((chararray)distanceAvg, '],');\r\n \r\nSTORE Displayed INTO '$output' USING PigStorage(',');

Running PigLatin script

\r\n

I am using Apache Pig 0.10.0 (the newest version of Apache Pig at the time of writting this post). You can read read about new features in Pig 0.10.0 here.

\r\n

My script takes five parameters i.e. input and output paths, song’s hotness treshold (a float number between 0.0 and 1.0), number of output songs and default level of parallelism.

\r\n\r\n

 

time /usr/lib/pig-0.10.0/bin/pig -p input=input/million-song -p hotness=0.5 -p topCount=200 -p parallel=100 -p output=output/million-song/all.5.200.100 exotic-songs.pig
\r\n\r\n

Pig runs this script as sequence of seven MapReduce jobs. The total time of running this script was 40m 47.758s. I have optimized this script by increasing memory available for child tasks, combining small input files, compressing the output of the map tasks and the output of the intermediate jobs using LZO compression. I have also turned off the speculative execution for both map and reduce tasks. Note, that there were no other jobs running on the Hadoop cluster at that time.

\r\n

I have run this script on the Hadoop cluster that belongs to ICM UW. I have used three “fat” slave nodes and a virtual machine on separate machine in the role of HDFS NameNode and Hadoop JobTracker. Each worker node has four AMD Opteron 6174 processors (48 cores in total), 192 GB of RAM and can store 7TB of data. For the purpose of this Pig script, I have configured each worker node to run 45 map and 35 reduce tasks maximally (so in total, I can run 135 map and 105 reduce tasks in parallel). I do realize that it is not typical Hadoop configuration (definitely, it is not commodity hardware), but I just simply use what I have. Currently, there is CDH3u3 installed here, which includes Hadoop 0.20.2, Pig 0.8.1 by default. I have have installed Pig 0.10.0 manually on my client machine and I have used it to sumbit jobs to this cluster.

\r\n

Future Optimizations

\r\n

The readability and performance of this script could be improved by implementing own user-defined functions (UDFs) e.g. multi-text concatenation, tuning some MapReduce and Pig parameters (e.g. pig.maxCombinedSplitSize) or setting better customized level of parallelism using PARALLEL keyword.

\r\n

Since I do not want to make this post to long, the effects of the refactorization and optimization will be described in detail in my next posts. I would like to write a couple of posts focused on the development and optimization of PigLatin scripts based on this example and the milion song dataset. I would mention what Pig tools and libraries one could use, show some benchmarks etc.

\r\n

The result to see

\r\n

The results can be visualized by using some JavaScipt with GoogleMaps. The map bellow shows 200 songs and for each song, I put a clickable marker in its artist’s lat/long localization, that displays basic information about this song and the link to a song’s preview.
\r\n

\r\n
\r\n

\r\n

The result to listen to

\r\n

Here are some songs that attracted my attention:

\r\n\r\n

If you find more interesting examples, just let me know or simply put them in the comments bellow. I do realize that my music taste can be questionable ;)

\r\n

Special thanks

\r\n

Since all my calculations were performed on the Hadoop cluster that belongs to ICM UW, I would like to give big thanks to the ICM’s staff for the possibility to use the cluster.

","author":{"id":1072823,"username":"kawaa","realname":null,"emailHash":"3f183da5dfee568cae35d9748bdb6cbe","avatar":"https://secure.gravatar.com/avatar/3f183da5dfee568cae35d9748bdb6cbe?d=identicon&r=PG","reputation":0},"activeRevisionId":543808,"revisionIds":[543807,543808],"lastActiveUserId":1072823,"lastActiveDate":1350866821000,"parentId":null,"parentAuthor":null,"originalParentId":null,"childrenIds":[],"commentIds":[],"marked":true,"topics":["architects","tutorial","big data","bigdata","apache pig"],"primaryContainerId":8,"containerIds":[7,8],"plug":"process-million-songs-find","wiki":false,"score":0,"depth":0},"enableThreadedComments":true,"portal":{"topic":{"id":"6129","type":"topic","creationDate":1434655079000,"creationDateFormatted":"06/18/2015 07:17 PM","name":"big data","createdBy":{"id":2,"username":"matt"},"parentTopics":[],"childTopics":[],"usedCount":3849},"blurb":"Big Data Analytics news and training resources from DZone, the trusted source for learning advanced software design, web development and devops best practices.","code":"big-data","id":3,"creationDate":1434673770000,"creationDateFormatted":"06/19/2015 12:29 AM","displayTitle":"Big Data Zone: News, tutorials & tools for Big Data/Analytics developers","title":"Big Data","new":false,"order":2,"shortTitle":"big-data-analytics-tutorials-tools-news","color":"green","pageTitle":"Big Data Analytics Tutorials, News & Jobs - DZone","active":true,"modificationDate":1437509342000,"modificationDateFormatted":"07/21/2015 08:09 PM"},"contentType":"article"}],"loadedStyles":[["/lib/bootstrap/bootstrap.less","/lib/font-awesome/font-awesome.less","/lib/fontello/css/fontello.css","/lib/fontello/css/animation.css","/lib/angular-ui/select.css","/lib/ngDialog/css/ngDialog.css","/less/ngDialog-theme.less","/lib/bootstrap-switch/bootstrap-switch.css","/less/dzone20.less","/less/fonts.less","/less/directives.less","/lib/slick/slick.css","/lib/bootstrap-slider/bootstrap-slider.css","/less/layout.less","/widgets/article/content/article-content.less","/widgets/article/infoBar/widget.less","/widgets/components/slider/widget.less","/widgets/content/commentsSlider/widget.less","/widgets/header/blackBar/widget.less","/widgets/header/main/header-common.less","/widgets/header/main/widget.less","/widgets/sidebar/content/list/list.less","/widgets/sidebar/tapBar/sidebar-list.less","/widgets/sidebar/tapBar/widget.less","/widgets/users/UserHomeMiniProfile/widget.less"]],"loadedScripts":[["/lib/jquery/jquery.js","/lib/lodash/lodash.js","/lib/moment/moment.js","/scripts/utils.js","/lib/angular/angular.js","/lib/angular/angular-sanitize.js","/lib/local-storage/angular-local-storage.js","/lib/bootstrap/bootstrap.js","/lib/angular-ui/bootstrap.js","/lib/angular-ui/select.js","/lib/bootstrap-switch/bootstrap-switch.js","/lib/ngDialog/js/ngDialog.js","/lib/angular-moment/angular-moment.js","/scripts/app.js","/scripts/socket.js","/scripts/services.js","/scripts/ui-services.js","/scripts/directives.js","/scripts/filters.js","/lib/angular-touch/angular-touch.min.js","/lib/elastic/elastic.js","/lib/ng-file-upload/angular-file-upload-all.js","/lib/angular-deckgrid/angular-deckgrid.js","/scripts/dzone.js","/scripts/ads.js","/scripts/head.js","/scripts/links.js","/scripts/utilities/directives.js","/scripts/utilities/services.js","/scripts/utilities/image-editor.js","/lib/bootstrap-slider/bootstrap-slider.js","/lib/bootstrap-slider/directive.js","/lib/angular-draganddrop/draganddrop.js","/widgets/article/content/utils.js","/widgets/article/infoBar/services.js","/widgets/components/slider/service.js","/widgets/header/main/angulartics-ga.js","/widgets/header/main/angulartics.js","/widgets/header/main/resize.js","/widgets/sidebar/content/list/service.js","/widgets/sidebar/tapBar/directive.js","/widgets/sidebar/tapBar/service.js"]],"TH_CSRF":"-2678805839586554234","botInfo":[{"isRenderBot":false}],"request":[{"site":{"id":7,"title":"DZone: Programming & DevOps news, tutorials & tools","keywords":"programming, software development, devops, java, agile, web, iot, database, mobile, big data, cloud","description":"Programming, Web Development, and DevOps news, tutorials and tools for beginners to experts. Hundreds of free publications, over 1M members, totally free.","name":"DZone.com"},"dev":false,"cdn":["dz2cdn1.dzone.com","dz2cdn2.dzone.com","dz2cdn3.dzone.com","dz2cdn4.dzone.com"],"theme":"dz20","context":"","user":{"id":2500002,"authenticated":false,"name":"Anonymous","realName":null,"avatar":"https://secure.gravatar.com/avatar/?d=identicon&r=PG","profile":"/users/2500002/anon-user.html"}}],"portals":[[{"topic":8,"id":2,"shortTitle":"agile-methodology-training-tools-news","color":"red","name":"Agile","code":"agile","url":"/agile-methodology-training-tools-news"},{"topic":6129,"id":3,"shortTitle":"big-data-analytics-tutorials-tools-news","color":"green","name":"Big Data","code":"big-data","url":"/big-data-analytics-tutorials-tools-news"},{"topic":30,"id":4,"shortTitle":"cloud-computing-tutorials-tools-news","color":"orange","name":"Cloud","code":"cloud","url":"/cloud-computing-tutorials-tools-news"},{"topic":59,"id":5,"shortTitle":"database-sql-nosql-tutorials-tools-news","color":"purple","name":"Database","code":"database","url":"/database-sql-nosql-tutorials-tools-news"},{"topic":31,"id":6,"shortTitle":"devops-tutorials-tools-news","color":"yellow","name":"DevOps","code":"devops","url":"/devops-tutorials-tools-news"},{"topic":1138,"id":7,"shortTitle":"enterprise-integration-training-tools-news","color":"green","name":"Integration","code":"integration","url":"/enterprise-integration-training-tools-news"},{"topic":48,"id":8,"shortTitle":"iot-developer-tutorials-tools-news-reviews","color":"orange","name":"IoT","code":"iot","url":"/iot-developer-tutorials-tools-news-reviews"},{"topic":1,"id":1,"shortTitle":"java-jdk-development-tutorials-tools-news","color":"purple","name":"Java","code":"java","url":"/java-jdk-development-tutorials-tools-news"},{"topic":29,"id":9,"shortTitle":"mobile-app-developer-tutorials-tools-news","color":"yellow","name":"Mobile","code":"mobile","url":"/mobile-app-developer-tutorials-tools-news"},{"topic":653,"id":10,"shortTitle":"apm-tools-performance-monitoring-optimization","color":"red","name":"Performance","code":"performance","url":"/apm-tools-performance-monitoring-optimization"},{"topic":35,"id":11,"shortTitle":"web-development-programming-tutorials-tools-news","color":"orange","name":"Web Dev","code":"webdev","url":"/web-development-programming-tutorials-tools-news"}]],"matchedUrl":{"name":"dzone:articles:view","mapping":"/articles/**","mappingPatterns":{}},"requiresModule":["angulartics","angulartics.google.analytics","dndLists","generalDirectives","monospaced.elastic","angularFileUpload","akoenig.deckgrid","ui.bootstrap-slider","ngSanitize","ui.select","ui.bootstrap","angularMoment","ngTouch","ngDialog","LocalStorageModule"]}; } catch(e) { console.error(e); }
4
Notification
  • Adam Van Grack started following you

  • Jessica Conaghan, Gumption Scott and 6 commented on a link you posted

    T-Mobile Unvells Cheaper, More Basic 'Simple Prepaid' Phone Plans

  • Jessica Conaghan replied on a comment you posted

    CSS counters are one of those "oh neat, didn't know CSS could do that" features with a lot of Xubuntu 14.10 Utopic Unicorn is the latest release of xubuntu based on Ubuntu 14.10

  • Jessica Conaghan started following you

See All
POWERED BY DZone TeamHub

\r\n
\r\n

\r\n

The result to listen to

\r\n

Here are some songs that attracted my attention:

\r\n\r\n

If you find more interesting examples, just let me know or simply put them in the comments bellow. I do realize that my music taste can be questionable ;)

\r\n

Special thanks

\r\n

Since all my calculations were performed on the Hadoop cluster that belongs to ICM UW, I would like to give big thanks to the ICM’s staff for the possibility to use the cluster.

","source":"http://hakunamapdata.com/process-a-million-songs-to-find-exotic-ones-with-apache-pig/","views":5166,"articleDate":1350866821000,"tldr":null,"originalSource":"http://hakunamapdata.com/process-a-million-songs-to-find-exotic-ones-with-apache-pig/","published":true,"nComments":0,"articleType":""}]; WMODEL_DATA.perms = {"canDecidePick":false,"canPublish":false}; WMODEL_DATA.isPreview = false; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('article.content', 'articleContent7', WMODEL_DATA, typeof controller == 'function' ? controller : null, [{name: 'partners', data: true},{name: 'DEFAULT', data: true}], ' oUhbblYOaqbcblYOaqbcC', null); })(); (function() { function controller($scope, $service, $location, SideBarService, TH$Request) { SideBarService.ctx.pageSize = $scope.pageSize; SideBarService.ctx.isPreview = $scope.isPreview; SideBarService.ctx.mode = $scope.mode; SideBarService.fn.loader = $service; SideBarService.fn.scrollCheck = function() { $scope.$emit('thIfScrollCheck'); }; var currentFilter; $scope.$on('$locationChangeSuccess', function() { if (!$location.search().filter) { $scope.filter = 'latest'; } else { $scope.filter = $location.search().filter; if ($scope.filter == 'latest') { $location.search('filter', null); } } if (currentFilter == $scope.filter) { return; } currentFilter = $scope.filter; SideBarService.ctx.filter = $scope.filter; }); $scope.display = SideBarService.getList(); $scope.$watchCollection(function() { return SideBarService.getList(); }, function (n) { $scope.display = n; }); $scope.isActive = SideBarService.isActive; $scope.isExcluded = SideBarService.isExcluded; $scope.loadMore = SideBarService.load; $scope.loading = function() { return SideBarService.ctx.loading; } } var WMODEL_DATA = {}; WMODEL_DATA.pageSize = 20; WMODEL_DATA.isPreview = false; WMODEL_DATA.OPTIONS = {}; WMODEL_DATA.mode = null; TH.installWidgetController('sidebar.content.list', 'sidebarContentList10', WMODEL_DATA, typeof controller == 'function' ? controller : null, [{name: 'DEFAULT', data: true}], ' oUhbkSMaaqbcdvVkcC', null); })(); (function() { var WMODEL_DATA = {}; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('sidebar.tapBar', 'sidebar', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhbkSMadabfWVcC oUhbkSMadabbWQbVkcC', null); })(); (function() { function controller($scope, shareThis, TH$Dialog, TH$Service) { $scope.getEditUrl = function(id, type) { if (!type || type == 'article') { return '/content/' + id + '/edit.html'; } else { return '/dzone/staff/' + type + (type == 'refcard' ? 'z' : 's') + '/' + id + '/edit.html'; } } $scope.share = function(socialNet, url, title){ shareThis.shareThis(socialNet, url, title); }; $scope.canDelete = function(article) { return article.canDelete; } $scope.edit = function(link) { TH$Dialog.open({ loadWidget: 'links.postPreview', widgetArgs: { edit: link.id }, size: 'xbig' }).then(function (result) { $scope.link.title = result.title; $scope.link.linkDescription = result.content; $scope.link.thumb = result.thumb; $scope.link.tags = result.topics; }); }; $scope.deleteLink = function(article) { var title = article.title; var type = 'link'; if(article.header){ title = (article.header.type == 'article') ? article.header.title : article.title; type = (article.header.type == 'article') ? 'article' : 'link'; } TH$Dialog.confirm('Do you want to delete "' + title + '"?').then(function() { return TH$Service.action('delete', {type: type, id: article.id}); }).then(function() { article.deleted = true; }); }; } var WMODEL_DATA = {}; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('content.commentsSlider', 'contentCommentsSlider9', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhbaqbcaibvnWffWVcC', null); })(); (function() { var WMODEL_DATA = {}; WMODEL_DATA.name = "commentsSlider"; WMODEL_DATA.slot = null; WMODEL_DATA.OPTIONS = {"name":"commentsSlider"}; TH.installWidgetController('components.slider', 'componentsSlider8', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhballbvbdSaoUhM', null); })();