弹弓:用于mpi的python包装器,用来“弹弓”一个小python或r函数来对付大数据的巨人

mpi-slingshot的Python项目详细描述


MPI吊索

一个python包装器,使用mpi在数千个文件中“弹弓”一个“石头”(函数)。

消灭大数据的巨人

我们是大卫。我们的数据是歌利亚。我们如何通过将代码扩展到数十万条文本上来杀死歌利亚?为此,我们编写一个小函数,一个“stone”,然后将其加载到弹弓中:然后程序负责将石头“扔”给数十万个文本文件。它的工作原理是克隆大卫,所以4,8,或128个大卫都是在同一时间投掷歌利亚。更具体地说,“stone”是一个接受文本文件路径的函数;该函数然后以任何方式读取和处理文本;然后以任何形式返回数据。然后,这些数据将被收集在一起,并以json和tsv(如果可能)的形式保存,后者可以直接在python/pandas、r和excel中打开。

在更专业的术语中,Slingshot基本上是一个极简的map/reduce框架:我们将一个函数同时“映射”到多个文本上,然后将数据“还原”回单个表示。但我从来没有发现“mapreduce”是一个非常令人印象深刻的图像,也没有对这个过程中真正发生的事情进行过很好的分析。鉴于:大卫克隆人与歌利亚战斗!更准确。

以交互方式运行(从这里开始)

在终端中运行:

。代码块:

弹弓

您应该看到一个提示:

。代码块:

        :o+s/+:                           .///`
      `d-o`+:/h+`                       .+y-``+o.
       d/+++/++om+:-                   +ho+yyo.`y-
      :y+oo+:/++hdoso/-               yh+/+/osy:s+
      -yy-/+o++osm``+o:+-           `/osyso+ooyd-
       -do/oo-:.`h.  .+::+`        /+//o-`-hhdms-
        -om.-`-- :h    :o-o-     .o-+-s-.. ss-s+++`
          s+ :`:- ss    .s-s.   /o`+.o../.ho   :ooo/
          `d- -`/. yo    `s-s `o/.+-+.-o/h:     `:soo-
           .h. - + `y+    `y:yo-:::/-:+ys`        `:oso.
            -y``-`/ `s+`   /ho::-/+:-+y:            `+os/
             -s`.--: `/s++ys+::++/.:s/`               -sss`
              -s`::.+` .:/::-- `-/s/`                  `soh.
               -o`-`:+ ``-..:`-ssh`                     `y/d`
                .s- .s    `.:yds:s`                      -y+y
                 +h- /  - `+/N:-h-+                       h`N`
                 m-` ``o. ` ss  oos.                      y.N-
                :d-:.:o- `:.m`   o+s`                     h-N`
                h/o`/+-  +`y+     oss`   `````           :soy
               -h-//-/  :-:h       oss:/+////+o+:.     `/s:m.
               d-+--+  `+`d.       `hsyy.`     .:+s/` -y+-d-
              /s `+ +  o.y:        oo./sh:       `/dyoy/+y.
             `d` o- / -/+o         d:  ..       .ydyysso:
             /s +/. .+-.y          :y-`         //sN:`
             d.o+`  `s y.           `+so/:--...-:sh-
            :yo:...:+.+-               -/++ooo++:.
            hoo::ooo-:y
           .m/s::/s/.d.
           `yoo///:.h-
             .ossoos.

Slingshot v0.1:交互模式(有关详细信息,请参阅“Slingshot--help”)

SLING: Path to the python or R file of code (ending in .py or .R) [numerical shortcuts for slings found in /oak/stanford/groups/malgeehe/code/mpi-slingshot/slings] (1) booknlp.py (2) count_words.R (3) count_words.py (4) prosodic_parser.py

系统将提示您输入“\sling\”,该文件是python或r代码。键入要从某些内置吊索中选择的数字,或键入指向自己代码的文件的路径。选择“吊索”后,将要求您提供“石头”:

。代码块:

STONE: The name of the function in the code that takes a string filepath (1) parse_chadwyck (2) postprocess_chadwyck

键入适当的(如果[rn only for python]),或者键入函数名“\stone”,stone是代码中的函数,或者是sling,它将被投射到文本上。它唯一需要的参数是文本文件的绝对路径:此函数将采用该路径,加载文本,并返回一些数据、任何数据。数据将在最后一起收集。

但是我们应该在哪些文本中使用这个函数呢?我们现在需要选择一个文件路径列表。

。代码块:

PATH: Enter a path either to a pathlist text file, or to a directory of texts [numerical shortcuts for pathlists found in /oak/stanford/groups/malgeehe/code/mpi-slingshot/slings] (1) paths_sherlock.chicago.txt (2) paths_sherlock.fanfic.txt (3) paths_sherlock.chadwyck_poetry.txt (4) paths_sherlock.chadwyck.1600_1900.txt (5) paths_ryan.chadwyck.1600_1900.txt (6) paths_sherlock.dime-westerns.txt

现在,我们提供一个文件列表给Slingshot(apathpath list\)。我们也可以这样做:

  • 为预定义的路径列表(在默认路径列表文件夹中找到的路径列表)键入数字。
  • 键入文件的路径(单击“自动完成”选项卡,双击“选项卡”列出文件)。此文件每行必须有一个绝对路径,仅此而已。
  • 键入目录的路径(点击Tab键可自动完成),然后提供文件扩展名(例如“txt”、“xml”):在这种情况下,将递归搜索目录,与该扩展名匹配的任何文件都将包含在文件路径列表中。

这就是我们所需要的!其他选项是可选的:

。代码块:

可选部分

SBATCH: Add to the SLURM/Sherlock process queue via sbatch? [N] (Y/N)

DEBUG: Do not run on MPI and do not submit with sbatch? [N] (Y/N)

SAVE: Save results? [Y] (Y/N)

SAVEDIR: Directory to store results in [results_slingshot/prosodic_parser/parse_chadwyck]

CACHE: Cache partial results? [Y] (Y/N)

QUIET: Print nothing to screen? [N] (Y/N)

LIMIT: Limit the number of paths to process to this number [None]

如果我们按回车键,将发生以下情况:

  • MPI将运行默认数量的CPU[4],以完成将提供的函数应用于路径列表中包含的所有文本。输出将打印到屏幕上。
  • 将在当前工作目录中创建一个名为results_slingshot/[sling]/[stone]的新文件夹。在这个文件夹中是output.txt,它是输出到屏幕的日志;而cmd.txt是交互式弹弓创建的实际命令。
  • 甚至实际上,当进程完成时,我们还将看到一个results.json和一个results.txt。它们表示流程的总结果,由原始路径收集和索引。

结果文件 ^^^^^^^^^^^^^

results.json


We should now also have two results files in the folder: results.json, which is a JSON file which looks like this:

.. code-block::

   [
   ["/...blah.../00022180.txt", {"count": 310725}],
   ["/...blah.../00004615.txt", {"count": 70321}],
   ["/...blah.../00021819.txt", {"count": 88483}],
   ]


results.txt
~~~~~~~~~~~

And results.txt, which has the same data but formatted as a TSV file. It reads:

.. code-block::

   _path   count
   /...blah.../00022180.txt    310725
   /...blah.../00004615.txt    70321
   /...blah.../00021819.txt    88483


But results.txt is different in one regard: to make results.txt, a tab-separated dataframe with (in this case) words as columns and texts as rows, we need to prune the number of columns, otherwise we’d have millions of them, and the file would become fat with empty cells (tab characters). By default, slingshot will limit the columns to the N most frequently found present in the data (in this case the N most frequent words). N can be set using the >> MFW prompt; it defaults to 10,000.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Grails中集成javaapplet   动态设置片段时发生java错误   JavaSpringVelocity模板电子邮件?   SpringHateOAS中java自定义json输出   java wait()和notify()相关问题   正则表达式中的单词边界是什么?   使用外部库将项目部署到glassfish后发生java NoClassDefFoundError   java为什么在这里初始化ListNode两次?   java libGDX移动三维模型   java使线程等待另一个线程的执行   正则表达式如何在java中使用正则表达式解析给定字符串   java SWT ScrolledComposite在32768像素后切断画布生成的图像