From 27830531c5c22ad18d0b62ff8f28ae96af60845c Mon Sep 17 00:00:00 2001 From: minervaning <61038128+minervaning@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:43:54 +0800 Subject: [PATCH] Deployed 218ce84 with MkDocs version: 1.4.3 --- 404.html | 32 ++--------------- App/24fall/index.html | 32 ++--------------- App/index.html | 38 +++------------------ App/nlp_phd/index.html | 32 ++--------------- App/zju_ling_cs/index.html | 32 ++--------------- CS/CPP/copy/index.html | 32 ++--------------- CS/CPP/course/index.html | 32 ++--------------- CS/CPP/file_io/index.html | 32 ++--------------- CS/CPP/final_review/index.html | 32 ++--------------- CS/CPP/inheritance/index.html | 32 ++--------------- CS/CPP/namespace/index.html | 32 ++--------------- CS/CPP/templates/index.html | 32 ++--------------- CS/CPP/type/index.html | 32 ++--------------- CS/OS/index.html | 32 ++--------------- CS/OS/mem_file/index.html | 32 ++--------------- CS/OS/overview/index.html | 32 ++--------------- CS/OS/process_syn/index.html | 32 ++--------------- CS/c_lang/index.html | 32 ++--------------- CS/coding_code/index.html | 32 ++--------------- CS/crawler/index.html | 32 ++--------------- CS/index.html | 32 ++--------------- CS/libgraphics/index.html | 32 ++--------------- CS/objdump/index.html | 32 ++--------------- CS/x86assm/index.html | 32 ++--------------- DL/NLPTech/bert_code/index.html | 32 ++--------------- DL/NLPTech/cs224n/index.html | 32 ++--------------- DL/NLPTech/cs231n/index.html | 32 ++--------------- DL/NLPTech/gpt_code/index.html | 32 ++--------------- DL/NLPTech/llama_code/index.html | 32 ++--------------- DL/NLPTech/ml_cheatsheet/index.html | 32 ++--------------- DL/NLPTech/rule_text/index.html | 32 ++--------------- DL/NLPTech/transformer_code/index.html | 32 ++--------------- DL/NLPTheory/autoregressive/index.html | 32 ++--------------- DL/NLPTheory/cot/index.html | 32 ++--------------- DL/NLPTheory/embodied_ai/index.html | 32 ++--------------- DL/NLPTheory/explainable_nlp/index.html | 32 ++--------------- DL/NLPTheory/index.html | 32 ++--------------- DL/NLPTheory/ling_ebender/index.html | 32 ++--------------- DL/NLPTheory/mwp/index.html | 32 ++--------------- DL/NLPTheory/neural_symbolic/index.html | 32 ++--------------- DL/NLPTheory/nli/index.html | 32 ++--------------- DL/Python/broadcastable_vector/index.html | 32 ++--------------- DL/Python/ipdb/index.html | 32 ++--------------- DL/Python/pandas_dataframe/index.html | 32 ++--------------- DL/Python/python_object/index.html | 32 ++--------------- DL/Python/pytorch/index.html | 32 ++--------------- DL/Python/setup_pack/index.html | 32 ++--------------- DL/Terminal/anaconda/index.html | 32 ++--------------- DL/Terminal/linux/index.html | 32 ++--------------- DL/Terminal/pytorch_terminal/index.html | 32 ++--------------- DL/Terminal/tmux/index.html | 32 ++--------------- DL/index.html | 32 ++--------------- Ling/Phonetics/reduction/index.html | 32 ++--------------- Ling/Phonetics/signal/index.html | 32 ++--------------- Ling/Pragmatics/ca_da/index.html | 32 ++--------------- Ling/Semantics/ambiguity/index.html | 32 ++--------------- Ling/Semantics/definitions/index.html | 32 ++--------------- Ling/Semantics/formal_semantics/index.html | 32 ++--------------- Ling/Semantics/index.html | 32 ++--------------- Ling/Syntax/conv_gen/index.html | 32 ++--------------- Ling/Syntax/ud_sud/index.html | 32 ++--------------- Ling/Syntax/uni_gram/index.html | 32 ++--------------- Ling/index.html | 32 ++--------------- Ling/pol_en_todo/index.html | 32 ++--------------- Ling/pol_zh/index.html | 32 ++--------------- Math/Graph/laplace_matrix/index.html | 32 ++--------------- Math/index.html | 32 ++--------------- Math/normal_forms/index.html | 32 ++--------------- Math/questions/index.html | 32 ++--------------- Other/apa/index.html | 32 ++--------------- Other/index.html | 32 ++--------------- Other/nlp_resources/index.html | 32 ++--------------- Other/tools/index.html | 32 ++--------------- Other/zotero/index.html | 32 ++--------------- index.html | 32 ++--------------- search/search_index.json | 2 +- sitemap.xml.gz | Bin 811 -> 811 bytes 77 files changed, 154 insertions(+), 2254 deletions(-) diff --git a/404.html b/404.html index 35c2da2c..f0600b88 100644 --- a/404.html +++ b/404.html @@ -52,17 +52,13 @@ - - -
+ - - @@ -107,30 +103,6 @@ - - @@ -280,7 +252,7 @@本章节包含升学经验和心得,已经完成 - ZJU英专转CS/NLP的心得
diff --git a/App/nlp_phd/index.html b/App/nlp_phd/index.html index 772a078c..7993efc8 100644 --- a/App/nlp_phd/index.html +++ b/App/nlp_phd/index.html @@ -58,17 +58,13 @@ - - - + - - @@ -118,30 +114,6 @@ - - @@ -291,7 +263,7 @@Hi there \ud83d\udc4b
"},{"location":"#_1","title":"\u6253\u62db\u547c\u7528\u7684","text":"\u6211\u7684BLOG\uff0c\u4e3b\u8981\u8bed\u8a00\u662f\u4e2d\u6587\uff0c\u4e3b\u8981\u5185\u5bb9\u6709\u7b14\u8bb0 + \u4e00\u4e9b\u778e\u8bdd
\u6211\u7684\u7b14\u8bb0\u4e0d\u591a\uff01\u4ee5\u540e\u4e5f\u4e0d\u4f1a\u591a\u7684\ud83d\ude24 \u6b22\u8fce\u6765\u770b\u6211\u7684\u7b14\u8bb0\uff01
\u5982\u679c\u60f3\u67e5\u627eZJU\u8bfe\u7a0b\u8d44\u6599\uff0c\u53ef\u4ee5\u914d\u5408\u4ed3\u5e93ZJU_COURSE_MATERIALS\u98df\u7528
\u6682\u65f6\u8fd9\u6837\u5206\u5de5
\u5927\u90e8\u5206\u5185\u5bb9\u8fd8\u5728\u4e00\u70b9\u4e00\u70b9\u65bd\u5de5\u4e2d\uff0c\u8bf7\u7a0d\u7b49\uff01
"},{"location":"#_2","title":"\u63a8\u8350\u9605\u8bfb","text":""},{"location":"#_3","title":"\u7533\u8bf7\u5fc3\u5f97","text":"\u4ece\u82f1\u4e13\u8f6cCS\u548cNLP\u7684\u5efa\u8bae\u5e16\uff01
"},{"location":"#computer-science-notes","title":"Computer Science Notes","text":"C\u5927\u7a0blibgraphics\u8e29\u5751\u6587\u6863 \uff08\u4f46\u5176\u5b9e\u9047\u5230\u7684\u5751\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u8fd9\u91cc\u5217\u51fa\u6765\u7684 \u6b22\u8fceissue\u6216\u90ae\u4ef6\u50ac\u66f4\uff01\uff09
C++\u542c\u8bfe\u7b14\u8bb0
OS\u64cd\u4f5c\u7cfb\u7edf\u7b14\u8bb0
"},{"location":"#deep-learning-notes","title":"Deep Learning Notes","text":"\u62b1\u6b49\uff0c\u8fd9\u680f\u5168\u662fTODO\uff0c\uff0c
"},{"location":"#linguistics-notes","title":"Linguistics Notes","text":"ZJU Semantics Notes \uff08\u867d\u7136\u6392\u7248\u4ecd\u4e0d\u662f\u5f88\u597d\u770b\u4f46\u53ef\u80fd\u662f\u5168\u7f51\u9996\u4e2a\ud83d\ude2d\uff09
"},{"location":"#_4","title":"\u5176\u5b83\u8bfe\u7a0b","text":"ZJU\u6253\u5f00\u827a\u672f\u4e4b\u95e8-\u94a2\u7434\u671f\u672b\u590d\u4e60\u7b14\u8bb0
"},{"location":"#_5","title":"\u5de5\u5177\u63a8\u8350","text":"\u5173\u4e8e\u6211\u600e\u6837\u5728\u7b14\u8bb0\u5de5\u5177Notion\u548cObsidian\u4e4b\u95f4\u505a\u9009\u62e9
"},{"location":"#_6","title":"\u8054\u7cfb\u4f5c\u8005","text":"\ud83d\udceb RuoxiNing@outlook.com \ud83e\uddd1\u200d\ud83d\udcbb https://ruoxining.github.io
"},{"location":"App/","title":"mu","text":"\u672c\u7ae0\u8282\u5305\u542b\u5347\u5b66\u7ecf\u9a8c\u548c\u5fc3\u5f97\uff0c\u5df2\u7ecf\u5b8c\u6210 - ZJU\u82f1\u4e13\u8f6cCS/NLP\u7684\u5fc3\u5f97
"},{"location":"App/24fall/","title":"\u3010TODO\u3011\u6211\u768424fall\u7533\u8bf7\u8bb0\u5f55","text":"\u672c\u9875\u9762\u4f1a\u5728\u621112\u6708\u6295\u9012\u5b8c\u7b2c\u4e00\u6279\u7533\u8bf7\u540e\u66f4\u65b0\u4e00\u4e2a\u7533\u8bf7\u8bb0\u5f55\u3002
\u4e3b\u8981\u76ee\u7684\u6709\u5206\u4eab\u6211\u7684\u7ecf\u9a8c\u5fc3\u5f97\u548c\u52aa\u529b\u83b7\u5f97\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u81f4\u529b\u4e8e\u7ef4\u62a4CS\u548clinguistics\u7533\u8bf7\u8d44\u6599\u5f00\u6e90\u7684\u751f\u6001\u3002
\u9884\u8ba1\u66f4\u65b0\u5c0f\u6807\u9898\u6709\uff1a
\u6211\u52a0\u5fc3\u9009\u5355\u4e3b\u8981\u770b\u7684\u98de\u8dc3+opencsapp\uff0c\u7136\u540e\u4ece\u91cc\u9762\u5220\u53bb\u6240\u6709\u7533\u5230\u4e5f\u4e0d\u60f3\u53bb\u7684
"},{"location":"App/24fall/#phd","title":"Ph.D. \u9009\u5bfc","text":""},{"location":"App/24fall/#_2","title":"\u8bed\u8a00\u6210\u7ee9","text":"CMU \u5fc5\u987b\u9001\u5206
Umich Meng ECE\u9700\u8981GRE\uff0c\u5fc5\u987b\u9001\u5206 The University of Michigan school code is 1839.
Uchi MPCS\u9700\u8981GRE\u7684q>85%\uff08\u597d\u50cf\u662f\u8fd9\u4e2a\u6570\uff09\uff0cv\u6ca1\u6709\u8981\u6c42 Please have an official TOEFL or IELTS score sent directly to the University of Chicago. The University's institution code for TOEFL/GRE reporting is 1832
UW CLMS \u5fc5\u987b\u8981\u5b98\u65b9\u9001\u5206 TOEFL/GRE ETS report code: 4854
USC: 4852
UCSD\uff1a4836
"},{"location":"App/24fall/#_3","title":"\u63a8\u8350\u4fe1","text":"\u5927\u7ea612.2\u53f7\u770b\u5230phd\u7533\u8bf7\u7fa4\u91cc\u8bf4\u7684\uff0c\u5176\u5b9e\u4e0d\u8981\u627e3\u4e2a\u63a8\u8350\u4eba\u5c31\u7ed3\u675f\uff0c\u6700\u597d\u63d0\u524d\u627e4\u52305\u4e2a\uff0c\u56e0\u4e3a\u591a\u4ea4\u6ca1\u6709\u5173\u7cfb\uff0c\u5927\u90e8\u5206\u5b66\u6821\u90fd\u6709\u6dfb\u52a0\u591a\u4e2a\u63a8\u8350\u4eba\u7684\u9009\u9879\uff08\u6211\u7684\u9009\u6821\u91cc\u53ea\u6709loo\u548cumich\u4e0a\u9650\u4e09\u4e2a\uff09\uff0c\u4f46\u662f\u7ecf\u5e38\u6709\u63a8\u8350\u4eba\u5fd9\u5fd8\u4e86\u7684\u60c5\u51b5\u3002\u518d\u95ee\u53e6\u4e00\u4e2a\u7fa4\uff0c\u5f97\u5982\u679c\u662fphd\uff0c\u4e0d\u4f1a\u56e0\u4e3a\u6709\u4e00\u4e2a\u63a8\u8350\u4eba\u5fd8\u4e86\u4ea4\u62d2\u4f60\uff0c\u4f46\u662f\u6709\u7684ms\u542c\u8bf4\u4e09\u5c01\u4ea4\u4e0d\u9f50\u5c31\u63d0\u4ea4\u4e0d\u4e86\uff08\u6211\u7684\u6682\u65f6\u6ca1\u9047\u5230\uff09\uff0c\u6216\u8005\u53ef\u80fd\u56e0\u6b64\u65e0\u58f0\u62d2\u4f60\uff0c\u6240\u4ee5\u8fd8\u662f\u63d0\u524d\u627e4\u4e2a\u4ee5\u4e0a\u3002
\u542c\u8bf4USC MSCS\u5b8c\u5168\u4e0d\u770b\u63a8\u8350\u4fe1\uff0c\u56e0\u4e3a\u4e5f\u4e0d\u6562\u591a\u8981\uff0c\u6211\u5c31\u4ea4\u4e86\u4e00\u5c01\uff0c\u8d4c\u3002\u3002\u3002\u3002
Uchi\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1
Rice\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1
CMU\u540c\u4e00\u4e2a\u7533\u8bf7\u7cfb\u7edf\u4e4b\u95f4\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1\uff0c\u6bd4\u5982MSCS\u548cPhD\u5171\u4eab\uff0cMLT\u90a3\u4e00\u5927\u4e32\u7684AI\u9879\u76ee\u5171\u4eab\u3002
UCSD\u7684ms\u548cphd\u4e4b\u95f4\u4e0d\u80fd\u5171\u4eab\u63a8\u8350\u4fe1\uff0c\u4f46\u662f\u636e\u8bf4cs ce master\u4e4b\u95f4\u662f\u4e92\u901a\u7684\uff0c\u8ddfgit\u4e0d\u4e92\u901a
Umich\u76ee\u524d\u53ea\u77e5\u9053\u81f3\u5c11ms\u548cmeng\u4e4b\u95f4\u4e0d\u80fd\u5171\u4eab\u63a8\u8350\u4fe1\u3002\u586b\u9519\u4e86\u53ef\u4ee5\u66f4\u6539\u63a8\u8350\u4eba\uff0c\u66f4\u6539\u540e\u65b0\u7684\u63a8\u8350\u4eba\u4f1a\u6536\u5230\u90ae\u4ef6\uff0c\u53ea\u662f\u5728\u4f60\u7684\u7533\u8bf7\u91cc\u8fd8\u662f\u663e\u793a\u539f\u6765\u63a8\u8350\u4eba\u3002
Waterloo\u7684\u63a8\u8350\u4fe1\u5728\u7b2c\u4e00\u6b65\u63d0\u4ea4\u540e1-3\u5929\u5185\u53d1\u51fa\uff0c\u7533\u8bf7\u4eba\u4e0d\u53ef\u51b3\u5b9a\u3002\u6211\u7684\u63a8\u8350\u4eba\u6700\u5feb\u6536\u5230\u7684\u662f\u63d0\u4ea4\u540e1\u5929\u5de6\u53f3\u3002\u4e4b\u540e\u5728ddl\u524d14\u5929\u548c7\u5929\u8fd8\u4f1a\u5404\u81ea\u52a8\u53d1\u4e00\u6b21\u50ac\u4fe1
\u7fa4\u91cc\u8bf4\u7684\uff1a\u8865\u5145\u4e00\u4e2a\u54e5\u5927cs ce ee\u4e5f\u662f\u5171\u7528\u3002\u5e94\u8be5\u662fms
"},{"location":"App/24fall/#_4","title":"\u5957\u74f7","text":"\u7f51\u4e0a\u8bf4\u5957\u5230\u74f7\u624d\u80fd\u7533\u3002\u7533\u8bf7\u8fc7\u7a0b\u4e2d\u5f97\u5230\u7684\u6d88\u606f\u662f\u5957\u74f7\u548c\u7533\u8bf7\u5e76\u4e0d\u5f3a\u76f8\u5173\uff0c\u6709\u6559\u6388\u5c31\u60f3\u7b49\u770b\u5230\u6c60\u5b50\u518d\u51b3\u5b9a\u7684\u60c5\u51b5\u3002
"},{"location":"App/24fall/#college-specific","title":"College-specific\u7f51\u7533\u7684\u5751","text":"CMU\u5982\u679c\u76f4\u63a5\u641c\u7d22 MLT application \u51fa\u73b0\u7684\u4ee5\u4e0b\u9875\u9762\u53ca\u7533\u8bf7\u94fe\u63a5\u662f\u627e\u4e0d\u5230MLT\u9879\u76ee\u7684
Application Management (cmu.edu) \u8fd9\u4e2a\u9875\u9762\u548c\u4ee5\u4e0b\u622a\u56fe\u662f\u6b63\u786e\u7684\uff0c\u540c\u7406mscv\u548cmsaii\u4ec0\u4e48\u7684\u9879\u76ee\u4e5f\u5728\u8fd9\u91cc\u7533\u8bf7\u3002
UWaterloo \u7684\u7533\u8bf7\u5206\u4e3a\u4e24\u4e2a\u9636\u6bb5\uff0c\u7b2c\u4e00\u4e2a\u9636\u6bb5\u8d76\u7d27\u4ea4\u4e86\u624d\u80fd\u5728\u7b2c\u4e8c\u4e2a\u9636\u6bb5\u4e0a\u4f20cv \u6587\u4e66 \u8bed\u8a00\u6210\u7ee9\u7b49\u4e1c\u897f\uff0c\u7b2c\u4e8c\u9636\u6bb5\u7684\u94fe\u63a5\u4f1a\u5728\u7b2c\u4e00\u9636\u6bb5\u540e2-4\u5929\u6536\u5230\u3002\u7b2c\u4e00\u4e2a\u9636\u6bb5\u4e00\u5b9a\u4e00\u5b9a\u8981\u6bd412.1\u63d0\u524d\u81f3\u5c11\u56db\u4e94\u5929\u4ea4
Umich\u7684\u7cfb\u7edf\u4e00\u5f00\u59cb\u56db\u4e94\u4e2a\u9875\u9762\u8981\u987a\u5e8f\u586b\u5b8c\uff0c\u540e\u9762\u7684\u9875\u9762\u624d\u80fd\u8df3\u7740\u586b
"},{"location":"App/24fall/#_5","title":"\u6587\u4e66","text":"\u5176\u5b9e\u6211\u4e2a\u4eba\u8ba4\u4e3a\u5728\u5ba1\u6587\u4e66\u65f6\u6bcf\u4efd\u6587\u4e665-10\u5206\u949f\uff0c\u53ef\u80fd\u6240\u6709\u4eba\u80fd\u4e00\u773c\u770b\u5230\u7684\u662f 1\uff09\u5c0f\u6807\u9898 2\uff09\u52a0\u7c97\u7684\u5173\u952e\u8bcd\u3002\u8bb2\u4e00\u4e2a\u4f8b\u5b50\u662f\u6211\u4e0a\u6b21\u53c2\u52a0\u4e00\u95e8\u8bfe\u7684group tutorial\u65f6\uff0c\u5f53\u65f6\u5c0f\u7ec4\u6210\u5458\u5408\u5199\u4e86\u4e00\u4efdrp\uff0c\u5176\u4e2d\u6211\u5199\u7684\u662f\u6700\u6666\u6da9\u7684lit review\uff0c\u5373\u4e13\u4e1a\u672f\u8bed\u5bc6\u5ea6\u6700\u9ad8\u8fd8\u53e5\u5b50\u6700\u957f\uff0c\u4f46\u662f\u6211\u7ed9\u6bcf\u4e2a\u5206\u4e3b\u9898\u52a0\u4e86\u5c0f\u6807\u9898\uff0c\u5176\u5b83\u540c\u5b66\u5199\u7684\u90e8\u5206\u6ca1\u6709\u52a0\u3002\u8001\u5e08\u5728\u4e0e\u6211\u4eec\u8c08\u8bdd\u7684\u95f4\u9699\u7784\u4e86\u51e0\u773c\u6211\u4eec\u7684\u6587\u4ef6\uff0c\u77ed\u77ed\u7684\u65f6\u95f4\u91cc\u5c31\u53ea\u770b\u8fdb\u53bb\u4e86lit review\u7684\u5c0f\u6807\u9898\uff0c\u70b9\u8bc4\u4e86\u4e00\u4e0b\u3002\u6240\u4ee5\u6211\u89c9\u5f97\u505a\u6e05\u6670\u7684\u5206\u6bb5\u548c\u5c0f\u6807\u9898\u5f88\u91cd\u8981\uff08\u8fd9\u91cc\u771f\u7684\u6709\u70b9\u50cf\u8bbe\u8ba1\u56db\u539f\u5219\uff0c\u5bf9\u6bd4/\u805a\u5408\uff09\uff0c\u5c24\u5176\u662f\u65f6\u95f4\u7cbe\u529b\u4e0d\u591f\u65f6\uff0c\u5176\u4e2d\u7684\u7ec6\u8282\u5185\u5bb9\u8bf4\u4e0d\u5b9a\u4e0d\u7528\u62a0\u592a\u7ec6\u3002
\u60f3\u7ed9\u70b9\u5199\u6587\u4e66\u65f6\u81ea\u5df1\u7528\u7684\u683c\u5f0f
PS\u7ed3\u6784
\u7b2c\u4e00\u6bb5\uff1a\u4e00\u4e9beye-catcher\uff0c\u8bb2\u4e00\u70b9\u5bf9\u81ea\u5df1\u603b\u7ed3\u6027\u7684\u8bdd/tattoo\uff0c\u6216\u8005\u5e72\u8106\u76f4\u63a5\u4ece\u201c\u6211\u672c\u79d1\u5f00\u59cb\u5bf9xxx\u611f\u5174\u8da3\uff0c\u4e8e\u662f\u4e0a\u4e86\u5f88\u591a\u8bfe\u505a\u4e86\u5f88\u591a\u7814\u7a76\u201d\u5e73\u5b9e\u5730\u5f00\u59cb
\u7b2c\u4e8c\u6bb5\uff1a\u4e00\u822c\u4e00\u4e24\u53e5\u8bdd\u5e26\u8fc7\u8bfe\u7a0b\uff0c\u6709\u7279\u522b\u51fa\u8272\u7684score\u6216coursework\u53ef\u4ee5\u5728\u8fd9\u91cc\u8bf4
\u7b2c\u4e09\u5230\u4e94\uff08\u6216\u56db\uff09\u6bb5\uff1a\u6bcf\u6bb5\u4e00\u4e2a\u7ecf\u5386\uff0c\u53ef\u4ee5\u603b\u5206\u603b\u5199\uff0c\u627e\u5230\u4e00\u4e2a\u8fd9\u6bb5\u7ecf\u5386\u6700\u60f3\u7a81\u51fa\u7684\u7279\u70b9/\u54c1\u8d28\uff0c\u7136\u540e\u56f4\u7ed5\u7740\u8bf4
\u7b2c\u516d\u6bb5\uff1amoving forward \u8bb2\u4ee5\u540e\u7684\u89c4\u5212
\u7b2c\u4e03\u6bb5\uff1awhy [program name] and why [school name]
\u7b2c\u516b\u4e5d\u6bb5\uff1a\u5982\u679c\u5b66\u6821\u6709\u7279\u6b8a\u7684diversity \u5956\u5b66\u91d1 gre clarification\u4e4b\u7c7b\u7684\u53ef\u4ee5\u5728\u8fd9\u91cc\u5199
References
SoP\u7ed3\u6784
\u7b2c\u4e00\u6bb5\uff1axxx\u662f\u5f88\u91cd\u8981\u7684\uff0c\u6211\u4e00\u76f4\u5bf9xxx\u611f\u5174\u8da3\uff0c\u6211\u9009\u62e9\u5728x\u6821\u8bfbphd is naturally a continuation of my previous interests and experiences\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u7684\u7814\u7a76\u5174\u8da3\u4e3a\uff1a ( \u6b64\u5904\u53ef\u4ee5\u6709\u5c0f\u6807\u9898\u548c\u4e00\u53e5\u8bdd\u4ecb\u7ecd
\u7b2c\u4e8c\u6bb5\uff1aAAA \u7ed3\u6784\u5982\u4e0b
\u5199\u5b8c\u4e00\u6574\u6bb5\u540e\u6700\u540e\u518d\u8d77\u5c0f\u6807\u9898\n\u4e00\u4e2a\u65b9\u5411\u6709\u591a\u91cd\u8981\u7b80\u4ecb\n\uff08+\u81ea\u5df1\u8fc7\u53bb\u8bfe\u7a0b\u9879\u76ee\uff0c\u5982\u679c\u771f\u7684\u5f88\u91cd\u8981\u7684\u8bdd\u5427\uff09\n+\u81ea\u5df1\u8fc7\u53bb\u7814\u7a76\n+\u81ea\u5df1\u8fc7\u53bb\u7814\u7a76\n+\u672a\u6765\u7814\u7a76\n+\u672a\u6765\u7814\u7a76\n+\u5e0c\u671bachieve\u7684\u76ee\u6807\n
\u7b2c\u4e09\u6bb5\uff1aBBB \u540c\u4e0a
\u7b2c\u56db\u6bb5\uff1aCCC \u540c\u4e0a\u4e0a
\u7b2c\u4e94\u6bb5\uff1aMoving forward
\u7b2c\u516d\u6bb5\uff1awhy [program name] and why [school name]
References
\u6211\u7684\u8fc7\u53bb\u7814\u7a76\u7ecf\u5386\u4e0e\u6211\u672a\u6765\u7684\u76ee\u6807\u65b9\u5411\u7279\u522b\u4e0d\u76f8\u4f3c\uff0c\u4f46\u662f\u611f\u89c9\u4f60\u5fc5\u987b\u53bb\u5bfb\u627e\u4e00\u4e2a\u5e73\u8861\u70b9\uff0c\u5bfb\u627e\u4e24\u4e09\u4e2a\u5c0f\u6807\u9898\u80fd\u628a\u4ed6\u4eec\u90fd\u6982\u62ec\u4f4f\u3002\u8fd9\u4e24\u4e09\u4e2a\u5c0f\u6807\u9898\u9996\u5148\u8981\u670d\u52a1\u4e8e\u672a\u6765\u65b9\u5411\uff0c\u7136\u540e\u56e0\u4e3a\u4f60\u8fc7\u53bb\u7684\u6bcf\u4e2a\u9879\u76ee\u4e0d\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u5c5e\u6027/\u9886\u57df\uff0c\u53ef\u4ee5\u9009\u62e9\u80fd\u591f\u670d\u52a1\u4e8e\u672a\u6765\u65b9\u5411\u7684\u65b9\u9762\uff0c\u7528\u201c\u6211\u53d7\u5230\u4e86xx\u65b9\u9762\u7684\u542f\u53d1\u201d\u4e4b\u7c7b\u7684\u8bdd\u8fde\u63a5\u8d77\u6765\u3002
UCSD \u7ed9\u7684\u53c2\u8003\u6307\u5bfc \u4e94\u4e2a\u95ee\u9898 - How did you become interested in this field? - What experiences have contributed toward your preparation for further study in this field? - What are your future goals? - What are your research interests? - How are you a \"match\" for the program to which you are applying? \u5176\u5b83\u8981\u6ce8\u610f\u7684 - Give examples of personal attributes or qualities that would help you complete graduate study successfully. - Describe your determination to achieve your goals, your initiative and ability to develop ideas, and your ability to work independently. - Describe background characteristics that may have placed you at an educational disadvantage (English language learner, family economic history, lack of educational opportunity, disability, etc.). - Leave the reader believing that you are prepared for advanced academic work and will be successful in graduate school.
"},{"location":"App/24fall/#_6","title":"\u81f4\u8c22","text":"\u6211\u7684\u63a8\u8350\u4eba
\u7ed9\u8fc7\u6211\u91cd\u8981\u4eba\u751f\u5efa\u8bae\u7684
\u8001\u5e08
\u8ddf\u6211\u804a\u7533\u8bf7\u7684\u540c\u5b66
\u63d0\u4f9b\u60c5\u611f\u652f\u6301\u7684\u540c\u5b66\u548cTA\u4eec
"},{"location":"App/24fall/#emotion-timeline","title":"\u9644\u5f55\uff1aEmotion \u7248 \u6211\u7684 Timeline\uff08\u5efa\u8bae\u522b\u770b \u770b\u6211\u4e22\u4eba\uff09","text":"\u6211\u7684\u7533\u8bf7\u771f\u7684\u597d\u6781\u9650\u554a\u554a\u554a\u554a\u554a\u554a\u554a
"},{"location":"App/nlp_phd/","title":"NLP Global PHD Equality Digest (\u642c\u8fd0)","text":"\u7ffb\u8bd1\u81eahttps://github.com/zhijing-jin/nlp-phd-global-equality
"},{"location":"App/nlp_phd/#_1","title":"\u9996\u63a8\u8d44\u6e90","text":"(John Hewitt, PhD@Stanford)\u00a0Undergrad to PhD, or not - advice for undergrads interested in research\u00a0(2018). [Suggestions]
\u7a77\u548c\u4e0d\u806a\u660e\u4e0d\u662f\u7406\u7531
\u7533\u8bf7\u524d\u76848\u6708\u52309\u6708\u8981\u5199\u597d\u81ea\u5df1\u7684SOP\uff0c\u601d\u8003\u81ea\u5df1\u8981\u505a\u600e\u6837\u7684\u7814\u7a76\uff0c\u600e\u6837\u8ba9\u81ea\u5df1\u7684\u7814\u7a76\u6709\u5f71\u54cd\u529b\u3002\u57288\u6708\u8981\u8054\u7cfb\u597d\u63a8\u8350\u4fe1
(Prof Jason Eisner@JHU)\u00a0Advice for Research Students\u00a0(last updated: 2021). [List of suggestions]
Interesting snippets: \"Goal-driven. Develop a vision of some new AI capabilities you\u2019d like to achieve, and solve problems that bring you closer to that goal.\", \"If you are working on incremental ideas, be aware that their usefulness depends on their complexity.\", \"Consider how the biggests bursts of impactful work tend to be tightly clustered in a small number of research groups and institutions. That\u2019s not because these people are dramatically smarter than everyone else, it\u2019s because they have a higher density of expertise and perspective, which puts them a little ahead of the rest of the community, and thus they dominate in generating new results.\", \"Early on in your career, I recommend splitting your time about evenly between textbooks and papers. You should choose a small set of relevant textbooks and theses to gradually work through, and you should also reimplement the models and algorithms from your favorite papers.\" 3. (Prof Fei-Fei Li@Stanford)\u00a0De-Mystifying Good Research and Good Papers\u00a0(2014). [Suggestions]
Interesting snippets: \"This means publishing papers is NOT about \u201cthis has not been published or written before, let me do it\u201d, nor is it about \u201clet me find an arcane little problem that can get me an easy poster\u201d. It\u2019s about \u201cif I do this, I could offer a better solution to this important problem,\u201d or \u201cif I do this, I could add a genuinely new and important piece of knowledge to the field.\u201d You should always conduct research with the goal that it could be directly used by many people (or industry). In other words, your research topic should have many \u2018customers\u2019, and your solution would be the one they want to use. A good research project is not about the past (i.e. obtaining a higher performance than the previous N papers). It\u2019s\u00a0about the future (i.e. inspiring N future papers to follow and cite you, N->\\inf).\"
"},{"location":"App/nlp_phd/#_10","title":"\u8bfb\u6587\u7ae0\u7684\u5de5\u5177","text":"\u672a\u5b8c\u5f85\u7eed\uff1a
"},{"location":"App/nlp_phd/#_13","title":"\u7b2c\u4e09\u9636\u6bb5\uff1a\u5de5\u4e1a\u754c\u7814\u7a76\u8005\u7684\u751f\u6d3b","text":""},{"location":"App/nlp_phd/#_14","title":"\u7b2c\u56db\u9636\u6bb5\uff1a\u5982\u4f55\u83b7\u5f97\u6559\u804c\uff1f\u5982\u4f55\u505a\u4e00\u4e2a\u597d\u5bfc\u5e08\uff1f","text":""},{"location":"App/nlp_phd/#nlp","title":"\u7b2c\u4e94\u9636\u6bb5\uff1a\u89c4\u5212NLP\u7684\u7814\u7a76\u751f\u6daf","text":""},{"location":"App/nlp_phd/#_15","title":"\u4e86\u89e3\u66f4\u591a","text":""},{"location":"App/nlp_phd/#_16","title":"\u5f15\u7528","text":"@misc{resources2021jin,\n author = {Zhijing Jin},\n title = {Resources to Help Global Equality for PhDs in NLP},\n year = {2021},\n publisher = {GitHub},\n journal = {GitHub repository},\n howpublished = {\\url{https://github.com/zhijing-jin/nlp-phd-global-equality}}\n}\n
"},{"location":"App/zju_ling_cs/","title":"ZJU English Major to CS&NLP","text":"\u26a0\ufe0f \u611f\u89c9\u5f53\u65f6\u5199\u5f97\u4e0d\u662f\u5f88\u597d\uff0c\u73b0\u5728\u5f88\u591a\u89c2\u5ff5\u53c8\u6709\u4e9b\u6539\u53d8\uff0c\u53ef\u80fd24\u5e74\u6625\u8282\u671f\u95f4\u7a7a\u4e0b\u6765\u4f1a\u518d\u8ba4\u771f\u6539\u4e00\u4e0borz
"},{"location":"App/zju_ling_cs/#_1","title":"\u672c\u6587\u6863\u662f\u4ec0\u4e48\uff1f","text":"\u7b14\u8005\u8f6c\u4e13\u4e1a\u8e29\u8fc7\u7684\u5751\u548c\u5bf9\u540e\u8f88\u7684\u5efa\u8bae\uff0c\u771f\u5fc3\u60f3\u5efa\u7acb\u8d77ZJU\u5185\u90e8\u826f\u597d\u7684\u4f20\u5e2e\u5e26\u6c1b\u56f4\u3002
"},{"location":"App/zju_ling_cs/#_2","title":"\u89c2\u5ff5&\u4e60\u60ef\u95ee\u9898","text":"\u5728\u5177\u4f53\u5efa\u8bae\u524d\u9996\u5148\u56de\u7b54\u4e00\u4e9b\u5e38\u6709\u7684\u62c5\u5fe7+\u505a\u4e00\u4e9b\u4e60\u60ef\u65b9\u9762\u7684\u63d0\u9192
"},{"location":"App/zju_ling_cs/#cs","title":"\u6211\u80fd\u8f6c\u5230CS\u5417\uff1f","text":"\u80fd\u3002\u6709\u5982\u4e0b\u6848\u4f8b\uff08\u4e0d\u4ee3\u8868\u6240\u6709\u4eba\u613f\u610f\u88ab\u8054\u7cfb\u5230\uff0c\u4e0d\u4fdd\u8bc1\u63d0\u4f9b\u8054\u7cfb\u65b9\u5f0f\uff09
\u60f3\u8c61\u4e00\u4e2a\u7b80\u5386 \u80fd\u5728\u7b80\u5386\u4e0a\u5f88\u663e\u773c\u548c\u4e00\u4e2a\u77ed\u8bed\u4ee5\u5185\u80fd\u8868\u8ff0\u7684\u7ecf\u5386\uff0c\u624d\u8981\u52aa\u529b\u53bb\u5237\u3002 \u6bd4\u5982\u76f8\u6bd4\u4e8e\u201c\u53cc\u4e13\u4e1a\uff0c\u662f\u4e00\u4e2azju\u7279\u6709\u7684\u8f85\u4fee\uff0c\u4e0d\u6c34\u7684\uff0c\u5b83\u8981\u6c42\u7684\u8bfe\u6bd4\u8f85\u4fee\u591a\uff0c\u4f8b\u5982\u6211\u4fee\u4e86xxx\uff0c\u6211\u53ea\u662f\u6ca1\u4feexxx\u201d\u548c\u201c\u4fee\u4e86\u4e00\u534aCS\u8bfe\u4e00\u534aAI\u8bfe\u201d\uff0c\u201cCS\u53cc\u5b66\u4f4d\u201d\u5c31\u66f4\u9002\u5408\u51fa\u73b0\u5728\u7b80\u5386\u4e0a\u3002
\u505a\u91cd\u5927\u51b3\u5b9a\u65f6\uff0c\u81f3\u5c11\u54a8\u8be220\u4e2a\u4eba\u7684\u5efa\u8bae\uff0c\u8981\u4e48\u54a8\u8be2\u4e86\u89e3n\u4e2a\u4eba\u5efa\u8bae\u7684\u4eba\uff08\u6bd4\u5982\u76f8\u5e94\u884c\u4e1a\u7684\u4eb2\u4eba\u670b\u53cb\u3001\u5b66\u751f\u5f88\u591a\u7684\u8001\u5e08\uff09\u6765\u62b5n\u4e2a\u4eba\uff0c\u603b\u4e4b\u603b\u548c\u8981\u62ff\u523020\u4e2a\u4eba\u5de6\u53f3\u7684\u5efa\u8bae\u3002
\u4e0d\u662f\u7684\u3002 - \u7406\u8bba\u4e0a\u662f\u5b8c\u5168\u53ef\u4ee5\u5b66\u597d\u7684\u3002NLP\u5708\u6709\u5f88\u591a\u7814\u7a76\u8005\u8bfb\u8fc7\u8bed\u8a00\u5b66\u548cCS\u53cc\u672c\u79d1\uff0c\u4ee3\u8868AP\u6709AllenNLP Noah Smitch, Colimbia University Zhou Yu\uff08ZJU\u7684\u672c\u79d1\uff09. \u8bfb\u8bed\u8a00\u5b66\u6ca1\u6709\u803d\u8bef\u4ed6\u4eec\u7684\u8111\u5b50\uff0c\u53cd\u800c\u662f\u4e00\u4e2a\u5f88\u597d\u7684idea\u6765\u6e90\u3002\u6211\u611f\u89c9\u6709\u5f88\u591a\u5929\u624d\u7684\u6848\u4f8b\u53ef\u4ee5\u8bc1\u660e\u4eba\u7684\u77e5\u8bc6\u5bb9\u91cf\u548c\u5b66\u4e60\u80fd\u529b\u4e0a\u9650\u662f\u8d85\u51fa\u5927\u5bb6\u60f3\u8c61\u7684\uff0c\u5b66\u4e24\u4e2a\u4e13\u4e1a\u8fd9\u4ef6\u5c0f\u4e8b\u8fdc\u8fdc\u5728\u8fd9\u4e2a\u4e0a\u9650\u4e4b\u4e0b\u3002\u6211\u6c38\u8fdc\u8ba4\u4e3a\u6bc5\u529b\u548c\uff08\u5bf9\u81ea\u5df1\u4eba\u751f\u4e0a\u9650\u7684\uff09\u60f3\u8c61\u529b\u6bd4\u5f53\u524d\u80fd\u529b\u66f4\u6709\u51b3\u5b9a\u4f5c\u7528\u3002 - \u5b9e\u9645\u82f1\u8bed\u4e13\u4e1a\u53bbCS\u53cc\u4e13\u4e1a\u5bb9\u6613\u5403\u4f4e\u7ee9\u70b9\u7684\u539f\u56e0\uff0c\u5f80\u5f80\u4e0d\u662f\u80fd\u529b\u667a\u529b\u4e0d\u8db3\uff0c\u800c\u662f\u6709\u4fe1\u606f\u5dee\uff1a\u751f\u6d3b\u5728\u6587\u79d1\u7684\u6563\u6f2b\u73af\u5883\u4e2d\u96be\u4ee5\u77e5\u9053\u5927\u90e8\u5206\u540c\u5b66\u7684\u81ea\u5b66\u8fdb\u5ea6\uff0c\u548c\u5982\u679c\u67d0\u4e9b\u8bfe\u7a0b\u6709\u5b9e\u8df5\u4e0a\u7684\u5751\uff0c\u6ca1\u6709\u4e0e\u5927\u90e8\u961f\u4e00\u8d77\u5b66\u4e60\u7684\u540c\u5b66\u5c31\u96be\u4ee5\u77e5\u9053\u600e\u6837\u7075\u6d3b\u5e94\u5bf9\u3002\u6240\u4ee5\u5efa\u8bae\u4e0e\u540c\u5b66\u4e00\u8d77\u5b66\u4e60\uff0c\u53c2\u89c1\u4e0b\u4e00\u6761\u3002
"},{"location":"App/zju_ling_cs/#cscs","title":"\u8981\u62e5\u6709\u4e00\u4e2a\u6216\u51e0\u4e2a\u540c\u6837\u8de8\u4e13\u4e1a\u5b66CS\u7684\u670b\u53cb\uff0c\u6216\u76f4\u63a5\u878d\u5165\u540c\u4e00\u7ea7\u7684CS\u672c\u79d1\u751f\u5708\u5b50\u91cc\u3002\u5982\u679c\u5b9e\u5728\u6ca1\u6709\uff0c\u4e00\u4e9b\u5176\u5b83\u5de5\u79d1\u7684\u540c\u5b66\u4e5f\u53ef\u4ee5\u3002","text":"\u540c\u5b66\u7684\u7528\u5904\u6709\uff1a - \u5e2e\u52a9\u4f60\u8ddf\u4e0a\u5b66\u4e60\u8282\u594f\u3002CS\u7684\u751f\u6d3b\u8282\u594f\u662f\u82f1\u8bed\u4e13\u4e1a\u76842\u500d\uff0c\u662f\u7406\u79d1\u4e13\u4e1a\u76841.5\u500d\uff0c\u5982\u679c\u51b3\u5b9a\u8f6c\u4e13\u4e1a\u662f\u9700\u8981\u4e3b\u52a8\u63d0\u9ad8\u4e00\u4e0b\u751f\u6d3b\u8282\u594f\u7684\uff0c\u505a\u4e8b\u79ef\u6781\u4e00\u70b9\uff0c\u544a\u522b\u62d6\u5ef6\u3002 - \u4e92\u76f8\u63a8\u8350\u597d\u7684\u81ea\u5b66\u8d44\u6599\uff0c\u4e92\u76f8\u5206\u4eab\u7b14\u8bb0\u548c\u8ba8\u8bba\u9898\u76ee\uff0c\u5206\u5de5\u6574\u7406\u671f\u672b\u590d\u4e60\u8d44\u6599\uff0c\u671f\u672b\u4e92\u76f8\u63d0\u95ee\uff0c\u5f62\u6210\u81ea\u5b66\u6c1b\u56f4\uff0c\u8282\u7701\u4e00\u4e9b\u8e29\u5751\u65f6\u95f4\u3002 - \u5982\u679c\u67d0\u4e9b\u8bfe\u7a0b\u5b89\u6392\u6709\u6559\u5b66\u4e8b\u6545\uff0c\u4f60\u53ef\u4ee5\u53ca\u65f6\u77e5\u9053\u5927\u90e8\u5206\u540c\u5b66\u662f\u600e\u6837\u5e94\u5bf9\u7684\uff0c\u53ca\u65f6\u8c03\u6574\u81ea\u5df1\u7684\u5e94\u5bf9\u63aa\u65bd\uff0c\u9632\u6b62\u5982\u679c\u6210\u7ee9\u5360\u6bd4\u7a81\u7136\u8c03\u6574\uff0c\u81ea\u5df1\u5c06\u52aa\u529b\u82b1\u5728\u4e86\u6700\u540e\u5360\u6210\u7ee9\u6bd4\u91cd\u5f88\u5c0f\u7684\u5730\u65b9\u3002
"},{"location":"App/zju_ling_cs/#_5","title":"\u8981\u591a\u8bb0\u7b14\u8bb0","text":"\u8bb0\u7b14\u8bb0\u662f\u8d39\u66fc\u5b66\u4e60\u6cd5\u7684\u6295\u5165\u4ea7\u51fa\u6bd4\u6700\u9ad8\u7684\u5b9e\u8df5\u5f62\u5f0f\uff0c\u5373\u65e2\u5e2e\u52a9\u68c0\u67e5\u7406\u89e3\uff0c\u7b14\u8bb0\u53c8\u9020\u798f\u540e\u4eba\u3002\u4f60\u53ef\u4ee5\u79c9\u627f\u5f00\u6e90\u7cbe\u795e\uff0c\u50cf\u524d\u8f88\u4e00\u6837\u591a\u5c06\u7b14\u8bb0\u516c\u5e03\u9020\u798f\u540e\u4eba\uff08\u4e0d\u8fc7\u8bf7\u9075\u5b88\u8bda\u4fe1\u5b88\u5219\uff09\u3002\u975e\u5e38\u5e0c\u671bZJU\u80fd\u9010\u6e10\u5f62\u6210\u8f83\u597d\u7684\u4f20\u5e2e\u5e26\u6c1b\u56f4\uff0c\u8ba9\u540e\u8f88\u4e5f\u6709\u826f\u597d\u6821\u53cb\u8d44\u6e90\u53ef\u4eab\u7528\u3002
"},{"location":"App/zju_ling_cs/#_6","title":"\u6211\u53ef\u4ee5\u4ee5\u600e\u6837\u7684\u8eab\u4efd\u672c\u79d1\u6bd5\u4e1a\uff1f\u6211\u6709\u54ea\u4e9b\u53ef\u884c\u7684\u51fa\u8def\uff1f","text":"\u4ee5\u4e0b\u8fd9\u4e9b\u90fd\u662f\u53ef\u80fd\u505a\u5230\u7684\uff0c\u6211\u4e5f\u5206\u522b\u5217\u51fa\u4e86\u6211\u8ba4\u4e3a\u9700\u8981\u51c6\u5907\u7684\u80cc\u666f\u3002 - \u51fa\u56fdms\uff1a\u7ee9\u70b9\uff0c\u6691\u7814/\u5b9e\u4e60 - \u51fa\u56fd\u76f4\u63a5phd\uff1a\u6691\u7814\uff0cpaper - \u672c\u6821\u76f4\u535a\uff1a\u7ee9\u70b9\uff0c\u8fdb\u672c\u6821\u7ec4\uff0c\u590f\u4ee4\u8425\uff0cpaper - \u8de8\u6821\u76f4\u535a\uff1a\u7ee9\u70b9\uff0c\u5bf9\u65b9\u6821\u590f\u4ee4\u8425\uff0cpaper - \u5de5\u4f5c\uff1a\u5237\u9898\uff0c\u5b9e\u4e60 \u5176\u4e2d\u6211\u8ba4\u4e3a\u503c\u5f97\u6ce8\u610f\u7684\u8fd8\u6709\uff0c\u5177\u4f53\u6700\u597d\u7531\u8bfb\u8005\u518d\u54a8\u8be2\u76f8\u5e94\u8eab\u4efd\u7684\u4eba\u7684\u5efa\u8bae\u3002\u672c\u6761\u9002\u7528\u524d\u9762\u6240\u8ff0\u201c20\u4e2a\u4eba\u5efa\u8bae\u201d\u51c6\u5219\u3002
"},{"location":"App/zju_ling_cs/#_7","title":"\u8bfe\u7a0b","text":""},{"location":"App/zju_ling_cs/#cs_4","title":"CS\u5fc5\u4fee\u8bfe","text":"\u9996\u5148\u8981\u660e\u786e\u4e00\u4e2a\u8ba4\u77e5\u95ee\u9898\uff1a\u8bfbCS\u53cc\u5b66\u4f4d\u662f\u4e00\u4e2a\u539f\u5b50\u6027\u7684\u4e8b\u52a1\uff0c\u8981\u4e48\u4e0d\u8bfb\uff0c\u8981\u4e48\u6309\u9700\u6c42\u8bfb\u5b8c\u6216\u8f85\u4fee\u6216\u53cc\u5b66\u4f4d\uff0c\u8fd9\u4e24\u79cd\u9009\u62e9\u90fd\u662f\u6295\u5165\u4ea7\u51fa\u6bd4\u8f83\u9ad8\u7684\uff1b\u6295\u5165\u4ea7\u51fa\u6bd4\u6700\u4f4e\u7684\u662f\u8bfb\u4e00\u534a\uff08\u5fae\u8f85\u4fee\u6216\u53cc\u4e13\u4e1a\uff09\u3002 \u8be5\u56fe\u4e2d\u9664\u6570\u7406\u57fa\u7840\u6a21\u5757\u4e0d\u662f\u53cc\u5b66\u4f4d\u5fc5\u4fee\uff0c\u5176\u5b83\u662f\u5fc5\u4fee\u3002 \uff08\u8fd9\u4e2a\u56fe\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u6709\u4e2a\u7ea2\u5708\uff0c\u627e\u4e0d\u5230\u539f\u56fe\u4e86\uff0c\u6279\u8bc4cyh\u540c\u5b66\u4e71\u753b\uff09
\u9009\u4e0d\u4e0aCS\u7684\u8bfe\u600e\u4e48\u529e\uff1f - \u6700\u6709\u6548\uff1a\u8865\u9009+\u5728\u8865\u9009\u7684\u51e0\u5929\u91cc\u7ebf\u4e0b\u53bb\u9009\u8bfe\u529e\u6216\u7ed9\u9009\u8bfe\u529e\u53d1\u90ae\u4ef6\u3002\u674e\u6653\u8001\u5e08\u548c\u5f20\u4f20\u534e\u8001\u5e08\u90fd\u5f88nice\uff0c\u8868\u793a\u81ea\u5df1\u5f88\u60f3\u9009\u8bfe\uff0c\u8ddf\u8001\u5e08\u8bf4\u660e\u539f\u56e0\u3002 - \u7b2c\u4e8c\u6709\u6548\uff1a\u5982\u679c\u4efb\u8bfe\u8001\u5e08\u5728\u8ba1\u9662\u8bdd\u8bed\u6743\u8f83\u5927\uff0c\u8bf7\u4efb\u8bfe\u8001\u5e08\u5e2e\u5fd9\u8ddf\u9009\u8bfe\u529e\u8bf4\uff0c\u80fd\u4fdd\u8bc1\u4f60\u9009\u4e0a\u8be5\u8001\u5e08\u7684\u8bfe\u3002 - \u7b2c\u4e09\u6709\u6548\uff1a\u9009\u8bfe\u65f6\u4e0eCS\u7684\u540c\u5b66\u5546\u91cf\uff0c\u505a\u51fa\u65f6\u95f4\u6b63\u597d\u7684\u4e00\u4e9b\u8bfe\u8868\u3002\u53ef\u80fd\u6d89\u53ca\u5230\u201c\u7528\u4e00\u4e9b\u8bfe\u5835\u4f4f\u53e6\u4e00\u4e9b\u8bfe\u201d\u8fd9\u79cd\u590d\u6742\u64cd\u4f5c\uff0c\u6240\u4ee5\u5408\u4f5c\u6bd4\u8f83\u5212\u7b97\u3002
\u600e\u4e48\u5b66\uff1f - ZJU\u8bfe\u7a0b\u5171\u4eab\u8ba1\u5212 https://github.com/QSCTech/zju-icicles - \u56fe\u7075\u73ed\u8bfe\u7a0b\u901f\u901a\u8ba1\u5212 https://github.com/ZJU-Turing/TuringCourses - \u4e00\u4f4d\u5b66\u957f\u7684\u4f18\u8d28\u7b14\u8bb0 \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4\uff01 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io) - \u4e00\u4f4d\u5b66\u957f\u7684\u4f18\u8d28\u7b14\u8bb0 https://github.com/Zhang-Each/CourseNoteOfZJUSE
"},{"location":"App/zju_ling_cs/#ai","title":"AI","text":"AI\u8bfe\u4e00\u822c\u6bd4CS\u8bfe\u597d\u9009\uff0c\u4f46\u662f\u5982\u679c\u9009\u4e0d\u4e0a\u4e5f\u8bf7\u9075\u7167\u4e0a\u6761\u4e2d\u7684\u5efa\u8bae\u3002 \u975e\u5fc5\u8981\u4e0d\u9009AI\u8bfe\uff0cAI\u8bfe\u6700\u5927\u7684\u6536\u83b7\u662f\u5728\u7b80\u5386\u4e0a\u4f5c\u4e3a\u4e00\u4e2a90+\u8bfe\u7a0b\u51fa\u73b0\uff0c\u57fa\u672c\u5b66\u4e0d\u5230\u4e1c\u897f\uff08\u9664\u4e86NLP\u8bfe\u6211\u611f\u89c9\u542c\u8bfe\u6536\u83b7\u633a\u5927\u7684\uff09\uff0c\u4e3b\u8981\u9760\u81ea\u5b66\u540e\u5377\u51fa\u5927\u4f5c\u4e1a\u3002
"},{"location":"App/zju_ling_cs/#_8","title":"\u8bed\u8a00\u5b66","text":"\u56e0\u4e3a\u82f1\u4e13\u57f9\u517b\u65b9\u6848\u8fd8\u662f\u8981\u6c42\u4fee\u5927\u91cf\u4e13\u4e1a\u8bfe\u7684\uff0c\u611f\u89c9\u53ef\u4ee5\u5c3d\u91cf\u628a\u8bed\u8a00\u5b66\u6a21\u5757\u591a\u4fee\u4e00\u70b9\uff0c\u6709\u4e9b\u5728\u8fdb\u7ec4\u7684\u65f6\u5019\u53ef\u80fd\u8fd8\u662f\u8ba4\u53ef\u7684\u3002 \u4ee5\u4e0b\u8bfe\u7a0b\u5982\u679c\u62ff\u4e86\u9ad8\u5206\u503c\u5f97\u5728\u7b80\u5386\u4e0a\u4e00\u63d0 - \u5f53\u4ee3\u8bed\u8a00\u5b66 - \u8bed\u97f3\u5b66 - \u53e5\u6cd5\u5b66 - \u5fc3\u7406\u8bed\u8a00\u5b66 - \u8bed\u4e49\u5b66 - \u8bed\u7528\u5b66 - \u8bed\u6599\u5e93\u8bed\u8a00\u5b66
"},{"location":"App/zju_ling_cs/#_9","title":"\u6570\u5b66","text":"\u5bf9\u4e8ePhD\u3001\u627e\u5de5\u548c\u56fd\u5185\u76f4\u535a\uff1a \u53ef\u80fd\u4e0d\u9700\u8981\u6570\u5b66\u3002\u3002\u3002\u8ba4\u4e3a\u6700\u597d\u4e0d\u8981\u989d\u5916\u9009\u6570\u5b66\u8bfe \u6211\u81f3\u4eca\u9047\u5230\u7684\u8001\u5e08\u6ca1\u6709\u56e0\u4e3a\u6211\u7b80\u5386\u4e0a\u4efb\u4f55\u6570\u5b66\u76f8\u5173\u7684\u4e1c\u897f\u800c\u5f55\u6211\u6216\u62d2\u6211\u7684\uff0c\u90fd\u662f\u53ea\u95ee\u7f16\u7a0b\u3002 CS\u4e13\u4e1a\u8bfe\u91cc\u7684\u79bb\u6563\u6570\u5b66\u548c\u8ba1\u7b97\u7406\u8bba\uff08\u548c\u53ef\u80fd\u8fd8\u6709\u6570\u903b\uff09\u5df2\u7ecf\u8db3\u591f\u57f9\u517b\u6570\u5b66\u601d\u7ef4\u3002 \u5982\u679c\u62c5\u5fc3\u6570\u636e\u5206\u6790\u548c\u7edf\u8ba1\u6280\u80fd\uff0c\u6587\u6570\u91cc\u636e\u8bf4\u5e94\u7528\u7edf\u8ba1\u5b66\u8fd9\u95e8\u8bfe\u7a0b\u6bd4\u9ad8\u7b49\u6570\u5b66\u597d\u4f7f\uff0c\u8fd8\u6709\u673a\u4f1a\u7684\u540c\u5b66\u53ef\u4ee5\u8bd5\u4e00\u4e0b\u3002
\u5bf9\u4e8ems\uff1a \u786e\u5b9e\u6709\u4e00\u4e9b\u9879\u76ee\u8981\u6c42\u4fee\u8fc7\u4e00\u4e9b\u6570\u5b66\u8bfe\u7a0b\uff0c\u4f8b\u5982\u521a\u770b\u5230SUTD\u7684ISTD ms\u8981\u6c42\u4e24\u5b66\u671f\u5fae\u79ef\u5206\uff0c\u4e00\u5b66\u671f\u7ebf\u4ee3\u548c\u4e00\u5b66\u671f\u6982\u7edf\uff0c\u8fd9\u79cd\u65e0\u7591\u662f\u6bd4\u8f83\u4e0d\u53cb\u597d\u7684\u9879\u76ee\u4e86\u3002 \u4e5f\u6709\u6bd4\u8f83\u53cb\u597d\u7684\u9879\u76ee\uff0c\u5317\u7f8e\u4e00\u4e9b0\u57fa\u7840\u8f6c\u7801\u9879\u76ee\u53ef\u53c2\u7167OpenCSapp\uff0c\u82f1\u56fd\u7684IC\u548cUCL\u5728\u524d\u5e74\u4e5f\u5f00\u4e86\u96f6\u57fa\u7840\u8f6c\u7801\u9879\u76ee\uff0c\u4e0d\u8fc7\u51fa\u8def\u548c\u542b\u91d1\u91cf\u9700\u8981\u81ea\u5df1\u8861\u91cf\uff0c\u8fd8\u662f\u5efa\u8bae\u201c\u54a8\u8be220\u4e2a\u4eba\u201d\u51c6\u5219\u3002\u4ee3\u8868dp\u662f18\u7ea7SJTU\u82f1\u8bed\u4e13\u4e1a\uff0c4\u6bb5\u79d1\u7814\u6216\u4e92\u8054\u7f51\u5382NLP\u4ea7\u54c1\u5b9e\u4e60\uff0c\u5c11\u91cf\u9ad8\u5206\u6570\u5b66\u548c\u7f16\u7a0b\u8bfe\u7a0b\uff0c\u7ee9\u70b990+ \u2192 IC CS ms
"},{"location":"App/zju_ling_cs/#_10","title":"\u7ee9\u70b9","text":"\u53c2\u7167\u8fd9\u4e9b\u9876\u4f1a\u90fd\u6709\u4ec0\u4e48track\uff0c\u4e0b\u9762\u662f\u6700\u8fd1\u4e00\u671f\u6bcf\u4e2atrack\u7684best paper - Best Papers - ACL 2023 (aclweb.org) - Best Paper Awards - emnlp 2022 (balhafni.github.io) - Transactions of the Association for Computational Linguistics (transacl.org) - Announcing the NAACL 2022 Best Paper Awards! - NAACL-HLT 2022
\u7279\u522b\u5730\uff0c\u60f3\u5230NLP\u91cc\u6bd4\u8f83\u7eaf\u8bed\u8a00\u5b66\u7684\u4e3b\u9898/\u65b9\u6cd5\u4e5f\u6709\u4e00\u4e9b\uff0c\u6709\u5982\u4e0b\u51e0\u4e2a \u4e3a\u4ec0\u4e48\u8981\u8bb2\u8fd9\u4e00\u5757\u56e0\u4e3a\u62c5\u5fc3\u4f60\u5728\u9762\u8bd5\u7684\u65f6\u5019\u4f1a\u9700\u8981\u5411\u8001\u5e08\u8bc1\u660e\u4f60\u7684\u53e6\u4e00\u90e8\u5206\u4e13\u4e1a\u77e5\u8bc6\u4e5f\u662f\u6709\u7528\u7684 \u4e00\u822c\u6b27\u6d32\u7684NLP\u4f1a\u504f\u8bed\u8a00\u5b66\u4e00\u70b9 - \u5b9e\u9a8c\u8bed\u97f3\u548c\u97f3\u7cfb\u5b66 - \u7528\u8bed\u8a00\u5b66\u77e5\u8bc6\u505a\u6570\u636e\u548c\u6570\u636e\u589e\u5f3a - AI\u4e2d\u7684\u4f26\u7406\u9053\u5fb7\u95ee\u9898 - \u7a00\u6709\u8bed\u8a00\u6316\u6398
"},{"location":"App/zju_ling_cs/#_12","title":"\u5982\u4f55\u9009\u5bfc\uff1f","text":"\u56fd\u5916\u5bfc\u5e08\uff1a\u5e38\u8bfb\u6bcf\u5e74\u7684\u9876\u4f1a\u6709\u610f\u601d\u8bba\u6587\uff0c\u5e76\u53c2\u7167CSRankings: Computer Science Rankings\uff0c\u5173\u6ce8\u5b66\u672f\u5708\u517b\u597d\u53f7\u540e\u5e38\u5237Twitter \u56fd\u5185\u6821\u5185\u5bfc\u5e08\uff1a\u5982\u679c\u6709\u60f3\u8be2\u95ee\u7684\u5bfc\u5e08\u540d\u5355\u53ef\u4ee5\u90ae\u4ef6\u95ee\u6211 \u9009\u5bfc\u6216\u8005\u8054\u7cfbPhD\u7684\u65f6\u5019\u5982\u679c\u63a5\u5230\u7684\u4efb\u52a1\u662f\u4e8c\u4f5c\u4e09\u4f5c\u5f80\u540e\uff0c\u5f88\u53ef\u80fd\u662f\u6253\u767d\u5de5\uff0c\u57fa\u672c\u53ef\u4ee5\u62d2\u7edd\u3002\u9664\u975e\u4f60\u8ba4\u4e3a\u4f60\u627f\u62c5\u7684\u5de5\u4f5c\u8f83\u4e3a\u91cd\u8981\uff0c\u8001\u5e08\u53ef\u4ee5\u7ed9\u4f60\u63a8\u8350\u4fe1\uff0c\u4e8c\u4f5c\u4e09\u4f5c\u7684\u4f5c\u7528\u53ef\u80fd\u6ca1\u6709\u63a8\u8350\u4fe1\u5927\u3002 \u5982\u679c\u7533\u8bf7PhD\uff0c\u63a8\u8350\u4fe1\u7684\u529b\u5ea6\uff1a\u4f60\u4e0e\u63a8\u8350\u4eba\u7684\u4ea7\u51fa\u5f88\u91cd\u8981+\u76ee\u6807PhD\u5bfc\u8ba4\u8bc6\u7684\u4eba > \u4f60\u4e0e\u63a8\u8350\u4eba\u7684\u4ea7\u51fa\u5f88\u91cd\u8981+\u76ee\u6807PhD\u5bfc\u4e0d\u8ba4\u8bc6\u7684\u4eba > \u5176\u5b83
"},{"location":"App/zju_ling_cs/#_13","title":"\u7533\u8bf7","text":"\u56e0\u4e3a\u4fdd\u7814\u548c\u627e\u5de5\u6211\u786e\u5b9e\u4e0d\u61c2\uff0c\u8fd9\u91cc\u6682\u65f6\u53ea\u5199\u7533\u8bf7\u4e86\u3002\u540e\u7eed\u6709\u8bf7\u5171\u540c\u4f5c\u8005\u6269\u5c55\u5185\u5bb9\u7684\u8ba1\u5212\uff0c\u5982\u613f\u610f\u8d21\u732e\u8bf7\u8054\u7cfb\u6211\u3002
"},{"location":"App/zju_ling_cs/#check-point","title":"Check Point","text":"\u5927\u4e00\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u4e13\u5fc3\u5b66\u4e13\u4e1a\u8bfe \u5927\u4e8c\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u8fdb\u7ec4\uff0c\u5b66\u4f1apytorch\uff0c\u8bad\u8fc7\u4e00\u4e9b\u5e38\u7528\u7684\u6a21\u578b \u5927\u4e09\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u4ea7\u51fa\u4e00\u4f5c\u6216\u5171\u4e00\u8bba\u6587
"},{"location":"App/zju_ling_cs/#_14","title":"\u6211\u8981\u4e0d\u8981\u627e\u4e2d\u4ecb\uff1f","text":"\u4e0d\u8981\u3002 \u539f\u56e0\u4e00\uff1aCS\u7684\u5728\u7ebf\u514d\u8d39\u8d44\u6599\u8db3\u591f\u4f7f\u7528 \u539f\u56e0\u4e8c\uff1a\u4e2d\u4ecb\u7684\u4fe1\u606f\u66f4\u65b0\u901f\u5ea6\u8d76\u4e0d\u4e0aCS\u5b66\u79d1\u7684\u53d1\u5c55\u901f\u5ea6
"},{"location":"App/zju_ling_cs/#_15","title":"\u6211\u7533\u8bf7\u53ef\u4ee5\u53c2\u8003\u54ea\u4e9b\u8d44\u6599\uff1f","text":"\u7533\u8bf7MS - \u5317\u7f8e\u7684CS master Home - Open CS Application - \u9664\u5317\u7f8e\u5916\u7684\u5176\u5b83CS master Global CS (global-cs-application.github.io) - \u4e00\u4ea9\u4e09\u5206\u5730/\u5bc4\u6258\u5bb6\u56ed\u7b49\u8bba\u575b - CC98\u4e0a\u6bcf\u4e00\u5e74CS\u7684\u98de\u8dc3\u624b\u518c
\u7533\u8bf7PhD - \u6b27\u7f8eNLP\u5708\u5bf9PhD\u7533\u8bf7\u7684\u5efa\u8bae https://github.com/zhijing-jin/nlp-phd-global-equality - \u4e86\u89e3\u5b66\u79d1\u4f18\u52bf\u5b66\u6821\u548c\u5bfc\u5e08 CSRankings: Computer Science Rankings - \u6ce8\u518c\u4e00\u4e2aTwitter\u8d26\u53f7\uff0c\u5f00\u59cb\u5173\u6ce8NLP\u5708\u7684PhD\u548cAP\uff0c\u5404\u79cd\u7533\u8bf7\u673a\u4f1a\u4ed6\u4eec\u90fd\u4f1a\u5c3d\u5feb\u53d1\u5e03\u7684\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5148\u4eceAndrew Ng\u3001Christopher Manning\u3001Geoffrey Hinton\u8fd9\u79cd\u8001\u6559\u6388\u5173\u6ce8\u8d77\uff0c\u7136\u540e\u5173\u6ce8\u4ed6\u4eec\u7684\u5173\u6ce8\u8fd9\u6837\u6765\u641e\u3002 - \u5173\u6ce8\u4e00\u4ea9\u4e09\u5206\u5730/CC98/\u4e00\u4e9b\u5fae\u4fe1\u516c\u4f17\u53f7/\u77e5\u4e4e\u7684\u62db\u751f\u4fe1\u606f
"},{"location":"App/zju_ling_cs/#_16","title":"\u6295\u9012\u6691\u7814\u6ce8\u610f\u4e8b\u9879","text":"\u6d41\u7a0b\u540c\u7533\u8bf7PhD \u5df2\u7ecf\u719f\u8bc6\u7684\u5bfc\u5e08\u63a8\u8350\u662f\u6700\u5feb\u7684\uff1b\u5426\u5219\u5c31\u81ea\u5df1\u6d77\u6295\uff0c\u6295\u53d1\u5e03\u8fc7\u62db\u751f\u5e7f\u544a\u6216\u4e3b\u9875\u8868\u660e\u6b63\u5728\u62db\u751f\u7684\u8001\u5e08\u662f\u6700\u5feb\u7684\u3002\u6709\u7684\u65f6\u5019\u53ef\u4ee5\u5c1d\u8bd5\u6295\u8ba4\u8bc6\u7684PhD\uff0c\u56e0\u4e3a\u6691\u7814\u671f\u95f4\u5927\u90e8\u5206\u60c5\u51b5\u8fd8\u662f\u8ddf\u7740PhD\u6253\u5de5\u3002 \u5982\u679c\u8001\u5e08\u7ed9\u4f60\u7684\u8d23\u4efb\u6bd4\u8f83\u91cd\uff0c\u4e14\u4f60\u6709\u6bd4\u8f83\u597d\u7684\u5de5\u4f5c\u73af\u5883\uff0c\u6211\u8ba4\u4e3a\u7ebf\u4e0a\u7ebf\u4e0b\u533a\u522b\u4e0d\u5927\u3002 \u60f3\u53bb\u5317\u7f8e\u5c31\u5957\u5317\u7f8e\uff0c\u6211\u89c9\u5f97\u6700\u597d\u4e0d\u8981\u627e\u8df3\u677f\uff0c\u6709\u5317\u7f8e\u7684\u7ebf\u4e0a\u6691\u7814\u4e5f\u5f88\u597d\uff0c\u53ea\u8981\u662f\u4f60\u4e00\u4f5c\uff0c\u65f6\u957f6\u4e2a\u6708\u4ee5\u4e0a\uff0c\u6bcf\u5468\u6c47\u62a5\u8fdb\u5ea6\u3002
"},{"location":"App/zju_ling_cs/#_17","title":"\u6295\u9012\u5b9e\u4e60\u6ce8\u610f\u4e8b\u9879","text":"\u9700\u8981\u5b9e\u4e60 iff \u4f60\u6253\u7b97\u627e\u5de5or\u8bfb\u5b8c\u7855\u58eb\u627e\u5de5\uff0c\u7533\u8bf7\u5b66\u672f\u7c7bms\u548cPhD\u7684\u8bdd\uff0c\u5b9e\u4e60\u4e0d\u5f3a\u6c42\u3002
"},{"location":"App/zju_ling_cs/#-xuan-insrgithubio","title":"- \ud83c\udff3\ufe0f\u200d\ud83c\udf08 \u603b\u89c8 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io) \u627e\u6691\u671f\u5b9e\u4e60\u548c\u79cb\u62db\u7684\u7ecf\u9a8c\u5e16","text":"http://www-cc98-org-s.webvpn.zju.edu.cn:8001/topic/4950730
"},{"location":"App/zju_ling_cs/#_18","title":"\u5173\u4e8e\u7b14\u8005&\u8054\u7cfb\u7b14\u8005","text":"\u7b14\u8005\u4f30\u8ba1\u662f\u4ece\u82f1\u8bed\u4e13\u4e1a\u8f6cNLP\u89c4\u5212\u6700\u4e0d\u987a\u3001\u8fdb\u5ea6\u6700\u66f2\u6298\u7684\u4e00\u4e2a\u3002\u8fd9\u4efd\u6587\u6863\u4e0d\u662f\u4ec0\u4e48\u6210\u529f\u7ecf\u9a8c\u5206\u4eab\uff0c\u6211\u5e76\u4e0d\u6210\u529f\uff0c\u53ea\u662f\u60f3\u628a\u6211\u8e29\u8fc7\u7684\u5751\u544a\u8bc9\u540e\u4eba\uff0c\u5e0c\u671b\u5c11\u6709\u4eba\u91cd\u8e48\u6211\u7684\u8986\u8f99\u3002\u6211\u89c9\u5f97\u6211\u7684\u9ad8\u4e2d\u548c\u672c\u79d1\u8fc7\u5f97\u592a\u574e\u5777\u4e86\uff0c\u771f\u8bda\u5730\u60f3\u5e2e\u52a9\u5b66\u5f1f\u5b66\u59b9\uff0c\u5e0c\u671b\u4f60\u4eec\u4e00\u5207\u987a\u5229\u3002\u8bfb\u8005\u53ef\u4ee5\u4ee5\u6211\u4f5c\u4e3a\u57fa\u51c6\uff0c\u5728\u56db\u5e74\u540e\u4e0d\u80fd\uff08\u5f53\u7136\u5982\u679c\u65e9\u505a\u89c4\u5212\uff0c\u4e00\u76f4\u5728\u52aa\u529b\uff0c\u4e5f\u4e0d\u4f1a\uff09\u6bd4\u6211\u66f4\u5dee\u3002\u6bd5\u7adf\u4e00\u6761\u8def\u8d70\u7684\u4eba\u591a\u4e86\uff0c\u540e\u4eba\u4e00\u5b9a\u662f\u8981\u8d8a\u8d70\u8d8a\u987a\u7684\u3002
\u5982\u6709\u5efa\u8bae\u6216\u7591\u95ee\u8bf7\u901a\u8fc7\u90ae\u4ef6\u8054\u7cfb\u6211 RuoxiNing@outlook.com\u3002
"},{"location":"CS/","title":"\u7d22\u5f15","text":"\u672c\u7ae0\u8282\u5305\u62ec\u8ba1\u7b97\u673a\u79d1\u5b66\u7b14\u8bb0
"},{"location":"CS/c_lang/","title":"C\u8bed\u6cd5","text":""},{"location":"CS/c_lang/#_1","title":"\u6307\u9488","text":"\u6570\u7ec4\u540d\u662f\u4e00\u4e2a\u6307\u9488\u5e38\u91cf \u6307\u5411\u6307\u9488\u7684\u6570\u7ec4\uff08\u4e8c\u7ea7\u6307\u9488\uff09
int a = 10;\nint *p = &a;\nint **p = &p;\n
\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488
char ccolor[][] = {\"red\", \"blue\", \"yellow\"};\n
\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e00\u884c\u90fd\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u5373ccolor+i\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u7b2ci\u884c\u7684\u4e00\u7ef4\u6570\u7ec4\uff0cccolor+i\u7c7b\u578b\u662f\u201c\u957f\u5ea6\u4e3a7\u7684\u4e00\u7ef4\u6570\u7ec4\u201d\u7684\u6307\u9488\u3002ccolor[i]\u662f\u4e00\u7ef4\u6570\u7ec4
"},{"location":"CS/c_lang/#_2","title":"\u6307\u9488\u8fdb\u9636","text":"\u7c7b\u578b\u540d* \u6307\u9488\u53d8\u91cf\u540d
\u6307\u9488\u7684\u503c\u6216\u5730\u5740\u503c
double a, x[10];\ndouble *p1, *p2;\n
p1\u548cp2\u90fd\u662f\u6307\u9488\uff1ap1\u7684\u57fa\u7c7b\u578b\u662fdouble\uff0cp2\u7684\u57fa\u7c7b\u578b\u662fdouble*\uff0c\u6b64\u65f6\u90fd\u8fd8\u6ca1\u6709\u786e\u5b9a\u5730\u5740\u503c\uff0c\u9700\u8981\u8d4b\u503c\u3002
// \u8bfb\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\nchar str[100], *s;\nscanf(\"%s\", s);\n// \u8bfb\u5165\u4e00\u4e2a\u6574\u6570\nint a, *p;\nscanf(\"%d\", p);\n// \u5f15\u7528\u6307\u9488\nint c, a = 2, *p;\nc = 3 + *p;\n
\u6307\u9488\u7684\u52a0\u6cd5\u5bf9\u5730\u5740\u503c\u7684\u5f71\u54cd
\u5730\u5740\u503c\u7684\u589e\u91cf = sizeof(\u57fa\u7c7b\u578b)
\u5b9a\u4e49 \u57fa\u7c7b\u578b p\u5f53\u524d\u6307\u5411\u5730\u5740 p+1 char *p char (1 byte) 20 21 short *p short (2 bytes) 40 42 long *p long (4 bytes) 80 84\u7406\u89e3\u8fd0\u7b97\u7b26[]
a[3]\u7b49\u4ef7\u4e8e3[a]\u7b49\u4ef7\u4e8e*(3+a)
\u4e8c\u7ef4\u6570\u7ec4\u4e0e\u884c\u6307\u9488
N\u4e2a\u4eba\u56f4\u6210\u4e00\u5708\uff0c\u7b2c\u4e00\u4e2a\u4eba\u4ece1\u5f00\u59cb\u62a5\u6570\uff0c\u62a5M\u7684\u5c06\u88ab\u6740\u6389\uff0c\u4e0b\u4e00\u4e2a\u4eba\u4ece1\u5f00\u59cb\u62a5\uff0c\u6700\u540e\u5269\u4e0b\u4e00\u4e2a\uff0c\u6c42\u6700\u540e\u7684\u80dc\u5229\u8005\u3002
"},{"location":"CS/c_lang/#_4","title":"\u666e\u901a\u89e3\u6cd5","text":"\u7528\u94fe\u8868\u6a21\u62df\u8fd9\u4e2a\u8fc7\u7a0b\uff0cN\u4e2a\u4eba\u770b\u4f5cN\u4e2a\u8282\u70b9\uff0c\u8282\u70b91\u6307\u5411\u8282\u70b92\uff0c\u8282\u70b92\u6307\u5411\u8282\u70b93\uff0c\u8282\u70b9N\u6307\u5411\u8282\u70b91.
\u6bcf\u62a5\u5230M\uff0c\u5c31\u5220\u9664\u8fd9\u4e2a\u6570\u3002\u7f3a\u70b9\u662f\u8981\u6a21\u62df\u6574\u4e2a\u6e38\u620f\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u9ad8\u8fbeO(nm)\u3002
"},{"location":"CS/c_lang/#_5","title":"\u516c\u5f0f\u6cd5","text":"\u9012\u63a8\u516c\u5f0f
\\[ f(N, M) = (f(N-1, M)+M)\\%N \\]\u5176\u4e2df(M, N) \u8868\u793a N \u4e2a\u4eba\u62a5\u6570\uff0c\u6bcf\u62a5\u5230 M \u65f6\u6740\u6389\u8fd9\u4e2a\u4eba\uff0c\u6700\u540e\u80dc\u5229\u8005\u7684\u7f16\u53f7\u3002
\u600e\u6837\u63a8\u5bfc\u8be5\u516c\u5f0f\u3002
f(11, 3)
\u95ee\u98981: \u5047\u8bbe\u77e5\u905311\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4e3a6\uff0c\u4e0b\u4e00\u8f6e10\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4e3a\uff1a\u7b2c\u4e00\u8f6e\u5220\u6389\u7f16\u53f7\u4e3a3\u7684\u4eba\u540e\uff0c\u6240\u6709\u4eba\u90fd\u5f80\u524d\u79fb\u52a8\u4e863\u4f4d\uff0c\u80dc\u5229\u8005\u4e5f\u5f80\u524d\u79fb\u52a8\u4e863\u4f4d\uff0c\u6240\u4ee5\u4e0b\u6807\u75316\u53d83.
\u95ee\u98982: \u5047\u8bbe\u5df2\u77e510\u4e2a\u4eba\u65f6\uff0c\u80dc\u5229\u8005\u4e0b\u6807\u4e3a3\uff0c\u90a3\u4e0b\u4e00\u8f6e11\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u662f\uff1f
\u53ef\u4ee5\u770b\u4f5c\u4e0a\u4e2a\u8fc7\u7a0b\u7684\u9006\u8fc7\u7a0b\uff0c\u5927\u5bb6\u90fd\u5f80\u540e\u79fb\u52a83\u4f4d\uff0c\u6240\u4ee5f(11, 3) = f(10, 3) + 3\u3002\u4e0d\u8fc7\u6709\u53ef\u80fd\u6570\u7ec4\u4f1a\u8d8a\u754c\uff0c\u6240\u4ee5\u6700\u540e\u6a21\u5f53\u524d\u4eba\u6570\u7684\u4e2a\u6570\uff0cf(11, 3) = (f(10, 3) + 3) %11
\u95ee\u98983: \u73b0\u5728\u6539\u6210\u4eba\u6570\u4e3aN\uff0c\u62a5\u5230M\u65f6\u628a\u4eba\u6740\u6389\uff0c\u6570\u7ec4\u662f\u600e\u6837\u79fb\u52a8\u7684\uff1f\u6bcf\u6740\u6389\u4e00\u4e2a\u4eba\uff0c\u4e0b\u4e00\u4e2a\u4eba\u6210\u4e3a\u5934\uff0c\u76f8\u5f53\u4e8e\u628a\u6570\u7ec4\u5411\u524d\u79fb\u52a8M\u4f4d\u3002\u82e5\u5df2\u77e5N-1\u4e2a\u4eba\u65f6\uff0c\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4f4d\u7f6ef(N-1, M)\uff0c\u5219N\u4e2a\u4eba\u65f6\uff0c\u5c31\u662f\u5f80\u540e\u79fb\u52a8M\uff0c\u8003\u8651\u5230\u6570\u7ec4\u8d8a\u754c\uff0c\u8981\u6a21N\uff0c\u5373f(N, M) = (f(N-1, M) + M) % N\u3002
int cir(int n, int m)\n{\nint p = 0;\nfor (int i=2; i<=n; i++)\n{\np=(p+m)%i;\n}\nreturn p+1;\n}\n
"},{"location":"CS/coding_code/","title":"\u7f16\u7a0b\u89c4\u8303\u6587\u6863\u6a21\u677f","text":"\u4e00\u4efd\u7528\u4e8eC\u5927\u7a0b\u7684\u7b80\u6613\u7f16\u7a0b\u89c4\u8303\u6587\u6863\u3002 \u4e3a\u7edf\u4e00\u5c0f\u7ec4\u6210\u5458\u5728\u8f6f\u4ef6\u5f00\u53d1\u8bbe\u8ba1\u8fc7\u7a0b\u4e2d\u7684\u4ee3\u7801\u98ce\u683c\uff0c\u65b9\u4fbf\u7ec4\u5458\u4e92\u76f8\u4e4b\u95f4\u534f\u4f5c\uff0c\u7279\u63d0\u51fa\u4ee5\u4e0b\u7f16\u7801\u89c4\u8303\u3002
"},{"location":"CS/coding_code/#_1","title":"\u6392\u7248\u89c4\u8303","text":"\u7f16\u7801\u89c4\u8303\u8bf4\u660e\u6587\u6863_\u7f16\u7801\u89c4\u8303\u6587\u6863_\u67ef\u897f\u6ca1\u79d1\u6c14\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/crawler/","title":"\u5199\u4e2a\u722c\u866bCrawler\ud83d\udd77\ufe0f\uff01","text":"\u89e3\u6790html\u7684\u6b65\u9aa4\uff1a - \u5c42\u6b21\u5316\u7684\u6570\u636e - \u6709\u591a\u4e2a\u89e3\u6790html\u7684\u4e09\u65b9\u5e93\uff0c\u5982\uff1alxml\uff0cbeautifulsoup\uff0chtmlparser
"},{"location":"CS/crawler/#requests","title":"requests","text":"import requests\n
\u53cd\u53cd\u722c\u7684
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\n
"},{"location":"CS/crawler/#beautifulsoup","title":"Beautifulsoup","text":""},{"location":"CS/crawler/#_1","title":"\u5b89\u88c5\u548c\u521d\u59cb\u5316","text":"pip install beautifulsoup4\n
\u89e3\u6790\u7684\u7b2c\u4e00\u6b65\u662f\u6784\u5efa\u4e00\u4e2abeautifulsoup\u5bf9\u8c61
from bs4 import BeautifulSoup\nsoup = BeautifulSoup(html_doc, 'html_parser')\n
"},{"location":"CS/crawler/#_2","title":"\u4ecb\u7ecd","text":"\u7b2c\u4e00\u4e2a\u53c2\u6570html_doc\u662f\u8bfb\u53d6\u7684html\u6587\u6863\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u89e3\u6790\u5668\uff0cbeautifulsoup\u652f\u6301\u4ee5\u4e0b\u89e3\u6790\u5668
\u89e3\u6790\u5668 \u4f7f\u7528\u65b9\u6cd5 \u4f18\u52bf \u52a3\u52bf Python\u6807\u51c6\u5e93 BeautifulSoup(markup, \u201chtml.parser\u201d) \u4e2d\u6587\u4e0d\u884c lxml HTML\u89e3\u6790\u5668 BeautifulSoup(markup, \u201clxml\u201d) \u5feb C\u8bed\u8a00\u5e93 lxml XML\u89e3\u6790\u5668 BeautifulSoup(markup, [\u201dlxml-xml\u201d]), BeautifulSoup(markup, \u201cxml\u201d) \u5feb C\u8bed\u8a00\u5e93 htmlSlib BeautifulSoup(markup, \u201chtml5lib\u201d) \u51c6 \u6162BeautifulSoup\u7c7b\u7684\u57fa\u672c\u5143\u7d20
\u57fa\u672c\u5143\u7d20 \u8bf4\u660e Tag \u6807\u7b7e\uff0c\u6700\u57fa\u672c\u7684\u4fe1\u606f\u7ec4\u7ec7\u5355\u5143\uff0c\u5206\u522b\u7528<>\u548c\u6807\u660e\u5f00\u5934\u548c\u7ed3\u5c3e Name \u6807\u7b7e\u7684\u540d\u5b57\uff0c\u5373\u5c16\u62ec\u53f7\u91cc\u7684\u5185\u5bb9 Attribute \u6807\u7b7e\u7684\u5c5e\u6027\uff0c\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178 NavigableString \u6807\u7b7e\u5185\u7684\u975e\u5c5e\u6027\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e00\u4e2aString Comment \u6807\u7b7e\u5185\u5b57\u7b26\u4e32\u7684\u6ce8\u91ca\u90e8\u5206\uff0c\u4e00\u79cd\u7279\u6b8a\u7684Comment\u7c7b\u578b"},{"location":"CS/crawler/#_3","title":"\u4f7f\u7528\u65b9\u6cd5","text":"\u8bbf\u95ee\u6807\u7b7e\uff1a\u7528soup.\u7684\u683c\u5f0f\uff0c\u6bcf\u6b21\u53ea\u80fd\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5339\u914d\u7684tag\u3002
soup = BeautifulSoup(html_doc, 'lxml')\nprint(soup.head) #<head><title>The Dormouse's story</title><head>\nprint(soup.head.title) # <title>The Dormouse's story</title>\nprint(soup.a) # <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\n
\u8bbf\u95ee\u591a\u4e2a\u6807\u7b7e\uff1b\u4f7f\u7528soup.find_all(\u2019\u2019)\u3002\u4f1a\u8fd4\u56de\u4e00\u4e2alist.
soup.find_all('a')\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>, <a class=\"sister\" href=\"http://example.com/lacie\" id=\"link2\">Lacie</a>, <a class=\"sister\" href=\"http://example.com/tillie\" id=\"link3\">Tillie</a>]\nsoup.find_all('a')[0]\n// <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\n
\u53ef\u4ee5\u5728find_all\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u8fc7\u6ee4\u6761\u4ef6\u3002
soup.find_all('a', text = 'Elsie')\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>]\nsoup.find_all('a', attrs = {'id': 'link1'})\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>]\nsoup.find_all('a', id = 'link1')\n// \u4f46\u662f\u8fd9\u6837\u5199\u4e0d\u9002\u7528\u4e8e\u6240\u6709\u5c5e\u6027\uff1f\nsoup.find_all('p', class_= 'title')\n// [<p class=\"title\"><b>The Dormouse's story</b></p>]\n// \u8fd9\u79cd\u662fCSS\u9009\u62e9\u5668\n
"},{"location":"CS/crawler/#_4","title":"\u8bbf\u95ee\u6807\u7b7e\u5185\u5bb9\u548c\u5c5e\u6027","text":"\u901a\u8fc7 name \u548c string \u53ef\u4ee5\u8bbf\u95ee\u6807\u7b7e\u7684\u540d\u5b57\u548c\u5185\u5bb9\uff0c\u901a\u8fc7 get \u548c\u4e2d\u62ec\u53f7\u64cd\u4f5c\u7b26\u53ef\u4ee5\u8bbf\u95ee\u6807\u7b7e\u4e2d\u7684\u5c5e\u6027\u548c\u503c\u3002
print(soup.a)\n## <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\nprint(soup.a['class'])\n## ['sister']\nprint(soup.a.get('class'))\n## ['sister']\nprint(soup.a.name)\n## 'a'\nprint(soup.a.string)\n## 'Elsie'\n
"},{"location":"CS/crawler/#_5","title":"\u89e3\u6790\u7f51\u9875","text":"import requests\nimport chardet\nfrom bs4 import BeautifulSoup\nheaders = {\n'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\nurl = \"\"\nrqg = requests.get(url, headers = hearders, timeout = 3.0)\nrqg.encoding = chardet.detect(rqg.content)['encoding'] # requests \u8bf7\u6c42\u8fc7\u7a0b\n# \u521d\u59cb\u5316HTML\nhtml = rqg.content.decode('utf-8')\nsoup = BeautifulSoup(html, 'lxml') # \u751f\u6210 BeautifulSoup \u5bf9\u8c61\nprint('\u8f93\u51fa\u683c\u5f0f\u5316\u7684BeautifulSoup\u5bf9\u8c61\uff1a', soup.prettify())\nprint('\u540d\u4e3atitle\u7684\u5168\u90e8\u5b57\u8282\u70b9\uff1a', soup.find_all(\"title\"))\nprint('title\u5b50\u8282\u70b9\u7684\u6587\u672c\u5185\u5bb9:', soup.title.string)\nprint('\u4f7f\u7528get_text()\u83b7\u53d6\u7684\u6587\u672c\u5185\u5bb9\uff1a', soup.title.get())\ntarget = soup.find_all('ul', class_ = 'menu') # \u6309\u7167CSS\u7c7b\u540d\u5b8c\u5168\u5339\u914d\ntarget = soup.find_all(id = 'menu') # \u4f20\u5165\u5173\u952e\u5b57id\uff0c\u641c\u7d22\u7b26\u5408\u6761\u4ef6\u7684\u8282\u70b9\ntarget = soup.ul.find_all('a') # \u6240\u6709\u540d\u79f0\u4e3aa\u7684\u8282\u70b9\n
"},{"location":"CS/crawler/#lxmlxpath","title":"lxml\u7684XPath","text":"lxml\u8fd9\u4e2a\u5e93\u540c\u65f6\u652f\u6301HTML\u548cXML\u7684\u89e3\u6790\uff0c\u652f\u6301XPath\u89e3\u6790\u65b9\u5f0f\uff0c\u89e3\u6790\u6548\u7387\u9ad8\u3002
\u4f7f\u7528xpath\u9700\u8981\u4ecelxml\u5e93\u4e2d\u5012\u5165etree\u6a21\u5757\uff0c\u9700\u8981\u4f7f\u7528html\u7c7b\u5bf9\u9700\u8981\u5339\u914d\u7684html\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\u3002
import requests\nimport chardet\nfrom lxml import etree\nheaders = {\n'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\nurl = \"\"\nrqg = requests.get(url, headers = hearders, timeout = 3.0)\nrqg.encoding = chardet.detect(rqg.content)['encoding'] # requests \u8bf7\u6c42\u8fc7\u7a0b\n# \u521d\u59cb\u5316HTML\nhtml = rqg.content.decode('utf-8')\nhtml = etree.HTML(html, parser = etree.HTMLParser(encoding = 'utf-8'))\n
\u5b89\u88c5\u9014\u5f84
pip install lxml\n
Xpath\u5e38\u7528\u7684\u8868\u8fbe\u5f0f
\u8868\u8fbe\u5f0f \u63cf\u8ff0 nodename \u9009\u53d6\u6b64\u8282\u70b9\u7684\u6240\u6709\u5b50\u8282\u70b9\u3002 / \u4ece\u6839\u8282\u70b9\u9009\u53d6\u3002 // \u4ece\u5339\u914d\u9009\u62e9\u7684\u5f53\u524d\u8282\u70b9\u9009\u62e9\u6587\u6863\u4e2d\u7684\u8282\u70b9 . \u9009\u53d6\u5f53\u524d\u8282\u70b9\u3002 \u2026 \u9009\u53d6\u5f53\u524d\u8282\u70b9\u7684\u7236\u8282\u70b9\u3002 @ \u9009\u53d6\u5c5e\u6027\u3002\u4f7f\u7528\u8868\u8fbe\u5f0f\u5b9a\u4f4dhead\u548ctitle\u8282\u70b9
result = html.xpath('head') ## \u901a\u8fc7\u540d\u79f0\u5b9a\u4e3ahead\u8282\u70b9\nresult1 = html.xpath('/html/heda/title') ## \u6309\u8282\u70b9\u5c42\u7ea7\u5b9a\u4f4dtitle\u8282\u70b9\nresult2 = html.xpath('//title') ## \u4e5f\u53ef\u4ee5\u5b9a\u4f4dtitle\u8282\u70b9\n
Xpath\u8c13\u8bcd\u5e38\u7528\u7684\u8868\u8fbe\u5f0f
\u8868\u8fbe\u5f0f \u7ed3\u679c xpath(\u2019/body/div[1]\u2019) \u9009\u53d6body\u4e0b\u7684\u7b2c\u4e00\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[last()]\u2019) \u9009\u53d6body\u4e0b\u6700\u540e\u4e00\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[last()-1]\u2019) \u9009\u53d6body\u4e0b\u5012\u6570\u7b2c\u4e8c\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[position()<3]\u2019) \u9009\u53d6body\u4e0b\u524d\u4e24\u4e2a\u8282\u70b9 xpath(\u2019/body/div[@class]\u2019) \u9009\u53d6body\u4e0b\u5e26\u6709class\u5c5e\u6027\u7684div\u8282\u70b9 xpath(/body/div[@class=\u201dmain\u201d]\u2019) \u9009\u53d6body\u4e0bclass\u5c5e\u6027\u4e3amain\u7684div\u8282\u70b9 xpath(\u201d/body/div[price>35]\u201d) \u9009\u53d6body\u4e0bprice\u5143\u7d20\u503c\u5927\u4e8e35\u7684\u8282\u70b9"},{"location":"CS/crawler/#request-html","title":"request-html","text":"requests-html\u7406\u89e3\u4e3a\u53ef\u4ee5\u89e3\u6790HTML\u6587\u6863\u7684request\u5e93
pip install requests-html\n
\u83b7\u53d6\u4e00\u4e2auser-agent
user_agent = requests_html.user_agent()\n
\u5bf9JavaScript\u7684\u652f\u6301\u662frequests-html\u6700\u5927\u7684\u4eae\u70b9\uff0c\u4f1a\u7528\u5230render\u51fd\u6570\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5b83\u4f1a\u5148\u4e0b\u8f7dChromium\uff0c\u7136\u540e\u4f7f\u7528Chromium\u6765\u6267\u884c\u4ee3\u7801\uff0c\u4f46\u662f\u4e0b\u8f7d\u7684\u65f6\u5019\u53ef\u80fd\u9700\u8981\u4e00\u4e2a\u68af\u5b50\u3002
\u793a\u4f8b
from requests_html import HTMLSession\nsession = HTMLSession()\ndef parse():\nr = session.get('http://www.qdaily.com/')\n# \u83b7\u53d6\u9996\u9875\u65b0\u95fb\u6807\u7b7e\u3001\u56fe\u7247\u3001\u6807\u9898\u3001\u53d1\u5e03\u65f6\u95f4\nfor x in r.html.find('.packery-item'):\nyield {\n'tag': x.find('.category')[0].text,\n'image': x.find('.lazyload')[0].attrs['data-src'],\n'title': x.find('.smart-dotdotdot')[0].text if x.find('.smart-dotdotdot') else x.find('.smart-lines')[0].text,\n'addtime': x.find('.smart-date')[0].attrs['data-origindate'][:-6]\n}\n
\u901a\u8fc7\u7b80\u77ed\u7684\u51e0\u884c\u4ee3\u7801\uff0c\u5c31\u53ef\u4ee5\u628a\u6574\u4e2a\u9996\u9875\u7684\u6587\u7ae0\u6293\u53d6\u4e0b\u6765\u3002
\u793a\u4f8b\u4e2d\u4f7f\u7528\u7684\u51e0\u4e2a\u65b9\u6cd5\uff1a
\u2460 find( ) \u53ef\u4ee5\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff1a
\u7b2c\u4e00\u4e2a\u53c2\u6570\u53ef\u4ee5\u662fclass\u540d\u79f0\u6216ID\u7b2c\u4e8c\u4e2a\u53c2\u6570first=True\u65f6\uff0c\u53ea\u9009\u53d6\u7b2c\u4e00\u6761\u6570\u636e
\u2461 text \u83b7\u53d6\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9
\u2462 attrs \u83b7\u53d6\u5143\u7d20\u7684\u5c5e\u6027\uff0c\u8fd4\u56de\u503c\u662f\u4e2a\u5b57\u5178
\u2463 html \u83b7\u53d6\u5143\u7d20\u7684html\u5185\u5bb9
\u4f7f\u7528requests-html\u6765\u89e3\u6790\u5185\u5bb9\u7684\u597d\u5904\u5728\u4e8e\u4f5c\u8005\u90fd\u9ad8\u5ea6\u5c01\u88c5\u8fc7\u4e86\uff0c\u8fde\u8bf7\u6c42\u8fd4\u56de\u5185\u5bb9\u7684\u7f16\u7801\u683c\u5f0f\u8f6c\u6362\u4e5f\u81ea\u52a8\u505a\u4e86\uff0c\u5b8c\u5168\u53ef\u4ee5\u8ba9\u4ee3\u7801\u903b\u8f91\u66f4\u7b80\u5355\u76f4\u63a5\uff0c\u66f4\u4e13\u6ce8\u4e8e\u89e3\u6790\u5de5\u4f5c\u672c\u8eab\u3002
"},{"location":"CS/libgraphics/","title":"C\u5927\u7a0b libgraphics \u6587\u6863 \u4f7f\u7528\u8bb0\u5f55","text":"\u26a0\ufe0f \u6ca1\u5199\u5b8c TODO
"},{"location":"CS/libgraphics/#_1","title":"\u5df2\u77e5\u95ee\u9898","text":"\u2192\u4fee\u6539Makefile.win\uff0c\u5728\u672b\u5c3e\u52a0\u5165\uff08\u81ea\u5df1\u5b9e\u8df5\u7684\u65f6\u5019\u8fd9\u6b65\u4e0d\u52a0\u597d\u50cf\u4e5f\u884c\uff09
gratest1.o:gratest1.c\n$(CC) -c gratest1.c -o gratest1.o $(CFLAGS)\n
graphics.h \u4ec5\u63d0\u4f9b\u4ee5\u4e0b\u5c11\u91cf\u753b\u56fe\u51fd\u6570\u63a5\u53e3
InitGraphics();\nMovePen(x, y);\nDrawLine(dx, dy);\nDrawArc(r, start, sweep);\nGetWindowWidth();\nGetWindowHeight();\nGetCurrentX();\nGetCurrentY();\n
\u6211\u4eec\u5c06\u5728\u4e0b\u9762\u4ecb\u7ecd\u8fd9\u4e9b\u63a5\u53e3\u7684\u7528\u6cd5\u3002
"},{"location":"CS/libgraphics/#_3","title":"\u521d\u59cb\u5316\u64cd\u4f5c","text":"\u5728main.c\u91cc\u9700\u8981\u8fdb\u884c\u5982\u4e0b\u521d\u59cb\u5316
#include \"graphics.h\"\n#include \"extragraph.h\"\n#include \"imgui.h\"\nvoid Main() // \u6ce8\u610f\u8fd9\u91cc\u9700\u8981\u4f7f\u7528\u5927\u5199Main\n{\nSet WindowTitle(\"Your Title\");\nInitGraphics(); // \u8c03\u7528\u4e86\u56fe\u5f62\u6a21\u5f0f\n}\n
InitGraphics(); \u8fd9\u4e2a\u51fd\u6570\u4f1a\u6253\u5f00\u4e00\u4e2a\u7a7a\u7684\u56fe\u5f62\u7a97\u53e3\u3002
"},{"location":"CS/libgraphics/#_4","title":"\u7a97\u53e3","text":"\u4ee5\u4e0b\u56db\u4e2a\u51fd\u6570\u90fd\u4e0d\u9700\u8981\u4f20\u5165\u53c2\u6570\uff0c\u5206\u522b\u8fd4\u56de\u7a97\u53e3\u5bbd\u3001\u9ad8\uff0c\u5f53\u524dX\u3001Y\u5750\u6807\u3002
GetWindowWidth();\nGetWindowHeight();\nGetCurrentX();\nGetCurrentY();\n
"},{"location":"CS/libgraphics/#_5","title":"\u597d\u7684\u7f16\u5199\u4e60\u60ef","text":"\u5e94\u8be5\u5148\u5b9a\u4e49\u4e00\u4e9b\u5e38\u91cf\uff0c\u7ed9\u8fd9\u4e9b\u5e38\u91cf\u53d6\u540d\u5b57
#define HouseHeight 2.0\n#define HouseWidth 3.0\n#define AtticHeight 0.7\n#define DoorWidth 0.4\n#define DoorKnobRadius 0.03\n#define DoorKnobInset 0.07\n#define PaneHeight 0.25\n#define PaneWidth 0.2\n#define FirstFloorWindows 0.3\n#define SecondFloorWindows 1.25\n
"},{"location":"CS/libgraphics/#_6","title":"\u753b\u56fe\u5f62\u7684","text":""},{"location":"CS/libgraphics/#movepen","title":"MovePen","text":"\u5c06\u7b14\u79fb\u52a8\u5230(x, y)\u8be5\u5750\u6807\u3002\u6ce8\u610f\u5f53\u753b\u56fe\u5f62\u65f6\uff0c\u540e\u9762\u51e0\u4e2a\u51fd\u6570\u7684\u76f8\u5bf9\u4f4d\u79fb\uff0c\u90fd\u662f\u76f8\u5bf9\u4e8e\u8fd9\u4e2a\u51fd\u6570\u8bbe\u7f6e\u7684\u7b14\u5750\u6807\u79fb\u52a8\u7684\u3002
MovePen(double x, double y);\n
"},{"location":"CS/libgraphics/#drawline","title":"DrawLine","text":"\u5728\u753b\u7ebf\u4e4b\u524d\u4e00\u5b9a\u8981MovePen();
DrawLine(double dx, double dy);\n
\u753b\u7ebf\u7684\u65b9\u5411\uff1a
\u6a2a\u5750\u6807\u6700\u5de6\u8fb9\u662f0\uff0c\u5411\u53f3\u589e\u5927
\u7eb5\u5750\u6807\u6700\u4e0b\u9762\u662f0\uff0c\u5411\u4e0a\u589e\u5927
\u53ef\u4ee5\u7406\u89e3\u4e3a\u6211\u4eec\u5728\u7b2c\u4e00\u8c61\u9650
"},{"location":"CS/libgraphics/#drawarc","title":"DrawArc","text":"\u5728\u753b\u5f27\u4e4b\u524d\u4e00\u5b9a\u8981MovePen();
DrawArc(double r, double start, double sweep);\n
"},{"location":"CS/libgraphics/#_7","title":"\u6211\u4eec\u5e94\u5f53\u628a\u753b\u77e9\u5f62\u5c01\u88c5\u6210\u4e00\u4e2a\u65b0\u7684\u51fd\u6570","text":"void DrawBox (double x, double y, double width, double height)\n{\nMovePen(x, y);\nDrawLine(0, height);\nDrawLine(width, 0);\nDrawLine(0, height);\nDrawLine(-width, 0);\n}\n
void DrawCenteredBox(double x, double y, double width, double height)\n{\nDrawBox(w - width/2, y - height/2, width, height);\n}\n
"},{"location":"CS/libgraphics/#_8","title":"\u753b\u5706\u7684\u51fd\u6570","text":"void DrawCenteredCircle(double x, double y, double r)\n{\nMovePen(x + r, y);\nDrawArc(r, 0, 360);\n}\n
"},{"location":"CS/libgraphics/#_9","title":"\u6587\u5b57","text":"\u4ece\u5f53\u524d\u4f4d\u7f6e\u5f00\u59cb\u8f93\u51fa\u6587\u672c\u4e32
DrawTextString(string);\n
\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u67d0\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6
double stringLen = TextStringWidth(string);
"},{"location":"CS/libgraphics/#_10","title":"\u67e5\u770b\u56de\u8c03\u51fd\u6570\u7c7b\u578b","text":"typedef void(* KeyboardEventCallback)(int key, int event);\n
"},{"location":"CS/libgraphics/#_11","title":"\u5b9a\u65f6\u5668","text":""},{"location":"CS/libgraphics/#_12","title":"\u65f6\u95f4\u56de\u8c03\u51fd\u6570","text":"registerTimerEvent(mytimer); //\u83b7\u53d6\u7535\u8111\u65f6\u949f\u4fe1\u606f\u8fd4\u56de\u7ed9mytimer\nstartTimer(0, (int)(1000/speed)); // \u8981\u8ba8\u8bba\u4f20\u8fdb\u6765\u7684timer\u662f\u4ec0\u4e48\n
"},{"location":"CS/libgraphics/#_13","title":"\u5b9a\u65f6\u5668\u6d88\u606f\u56de\u8c03\u51fd\u6570","text":"void TimerEventProcess(int timerID);\n
\u793a\u4f8b
typedef enum\n{\nLabelTimer,\nBoxTimer,\n} MyTimer;\n
void mytimer(int timerID)\n{\nswitch (timerID)\n{\ncase LabelTimer:\nlabel_x += 0.5;\nif (label_x > 5.0) label_x = 1.0;\ndisplay();\nbreak;\ncase BoxTimer:\nbox_y += 0.5;\nif (box_y > 5.0) box_y = 1.0;\ndisplay();\nbreak;\nbreak;\n}\n}\n
registerTimerEvent(mytimer);\nstartTimer(LabelTimer, 100);\nstartTimer(BoxTimer, 200);\n
"},{"location":"CS/libgraphics/#_14","title":"\u9f20\u6807","text":""},{"location":"CS/libgraphics/#_15","title":"\u9f20\u6807\u6d88\u606f\u56de\u8c03\u51fd\u6570","text":"void MouseEventProcess(int x, int y, int button, int event);\n
x, y - \u4f4d\u7f6e\u5750\u6807
button - \u6309\u4e0b\u7684\u662f\u54ea\u4e2a\u952e
event - \u6309\u4e0b\uff0c\u677e\u5f00\uff0c\u79fb\u52a8\u7b49\u4e8b\u4ef6
void myMouseEvent (int x, int y, int button, int event)\n{\nmouse_x = ScaleXInches(x); // \u8fd9\u4e2a\u51fd\u6570\u5728extragraph\u5e93\u91cc\nmouse_y = ScaleYInches(y);\ndisplay();\n}\n
\u9700\u8981\u5728Main()\u91cc\u6dfb\u52a0\u8fd9\u4e00\u884c
registerMouseEvent(myMouseEvent);\n
\u5728display()\u91cc
void display()\n{\ndouble w = 1.0;\ndouble h = GetFontHeight() * 2;\n// \u6e05\u9664\u5c4f\u5e55\nDisplayClear();\n// draw a square\nSetPenColor(\"Red\");\ndrawLabel(label_x, label_y, \"Lable is Here\");\n//draw a rect/box to trace the mouse\n//drawRectangle(mouse_x, mouse_y, w, h, 0);\nSetPenColor(\"Blue\");\ndrawBox(mouse_x, mouse_y, w, h, 1, \"This box follows the mouse\", 'L', \"Red\");\n}\n
"},{"location":"CS/libgraphics/#linkedlist","title":"\u4f7f\u7528linkedlist\u5e93","text":"#include \"linkedlist.h\"\n
\u521b\u5efa\u4e00\u4e2a linkedlist \u540d\u53eb g_polylines
linkedlistADT g_polylines = NULL;\ng_polylines = NewLinkedList();\ndisplay();\n
void display()\n{\nlinkedlistADT poly = NextNode(g_polylines, g_polylines);\nSetPenColor(\"Blue\");\nif (poly) {\nPoint * p = (Point*) NodeObj(g_polylines, poly);\ndouble lx = p->x;\ndouble ly = p->y;\nMovePen(lx, ly);\nwhile (poly = NextNode(g_polylines, poly))\n{\np = (Point*) NodeObj(g_polylines, poly);\nDrawLine(p->x - lx, p->y - ly);\nlx = p->x;\nly = p->y;\n}\n}\n}\n
"},{"location":"CS/libgraphics/#button","title":"\u4f7f\u7528button\u548c\u952e\u76d8","text":"\u8fd9\u6b21\u9700\u8981\u7528\u5230\u7684\u5e93
#include <windows.h>\n#include <winuser.h>\n#include \"graphics.h\"\n#include \"extgraph.h\"\n#include \"imgui.h\"\n#include \"linkedlist.h\"\n
"},{"location":"CS/libgraphics/#_16","title":"\u5b57\u7b26\u8f93\u5165\u56de\u8c03\u51fd\u6570","text":"void charEventProcess(char c);\n
c - \u8f93\u5165\u5b57\u7b26\u7684ASCII\u7801
"},{"location":"CS/libgraphics/#_17","title":"\u952e\u76d8\u56de\u8c03\u51fd\u6570","text":"void KeyboardEventProcess(int key, int event);\n
key - \u54ea\u4e2a\u952e
event - \u6309\u4e0b\u8fd8\u662f\u677e\u5f00
\u793a\u4f8b
\u5728Main()\u4e2d
\n
void myKeyboardEvent(int key, int event)\n{\nuiGetKeyboard(key, event); // needed for using simpleGUI\ndisplay();\nswitch (event)\n{\ncase KEY_UP:\nif (key == VK_F1)\ng_add_point = !g_add_point;\nbreak;\ndefault:\nbreak;\n}\n}\n
"},{"location":"CS/libgraphics/#_18","title":"\u989c\u8272\u5e93","text":"\u81ea\u5e26\u7684\u989c\u8272\u5217\u8868
char colorlist[100][100] = {\u201dBlack\u201d, \u201cDark Gray\u201d, \u201cGray\u201d, \u201cLight Gary\u201d, \u201cWhite\u201d, \u201cBrown\u201d, \u201cRed\u201d, \u201cOrange\u201d, \u201cYellow\u201d, \u201cGreen\u201d, \u201cBlue\u201d, \u201cViolet\u201d, \u201cMagenta\u201d, \u201cCyan\u201d};\nconst int colorNumber = 14;\n
\u81ea\u5b9a\u4e49\u989c\u8272
\u989c\u8272\u4f1a\u88ab\u52a0\u5165\u989c\u8272\u5e93\uff0cRGB\u7684\u53d6\u503c\u8303\u56f4\u90fd\u662f[0, 1]\u800c\u4e0d\u662f[0, 256)
DefineColor(\"Color Name\", R, G, B);\n
"},{"location":"CS/libgraphics/#libgraphics","title":"libgraphics\u5176\u5b83\u5e38\u7528\u7684\u4e1c\u897f","text":""},{"location":"CS/objdump/","title":"Objdump\u5de5\u5177","text":"\u6e90\u4ee3\u7801\u6587\u4ef6\u540dmytest.c
gcc -c -g -o mytest mytest.c\nobjdump -s -d main.o > main.o.txt\n
\u76ee\u6807\u6587\u4ef6\u53cd\u6c47\u7f16\uff0c\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -c -o main.o main.c\nobjdump -S -d main.o > main.o.txt\n
\u663e\u793a\u6e90\u4ee3\u7801\u7684\u540c\u65f6\u663e\u793a\u884c\u53f7
objdump -j .text -ld -C -S main.o > main.o.txt\n
\u53ef\u6267\u884c\u6587\u4ef6\u53cd\u6c47\u7f16
gcc -o main main.c\nobjdump -s -d main > main.txt\n
\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -o main main.c\nobjdump -S -d main > main.txt\n
"},{"location":"CS/x86assm/","title":"x86\u6c47\u7f16","text":""},{"location":"CS/x86assm/#lab","title":"Lab\u8bb0\u5f55","text":"\u26a0 Lab\u5df2\u7ecf\u5168\u90e8\u6362\u6389\uff0c\u8fd9\u90e8\u5206\u4f5c\u4e1a\u4ecb\u7ecd\u65e0\u6cd5\u53c2\u8003\u4e86\u3002 1. \u4f5c\u4e1a1: \u5b57\u7b26\u4e32\u8f6c\u6362 \u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5c0f\u5199\u5b57\u6bcd\u5168\u90e8\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\uff0c\u5220\u9664\u7a7a\u683c\u540e\u8f93\u51fa\u3002 \u8bb0\u5f97\u4ed6\u6709\u5b57\u7b26\u4e32\u8bfb\u5199\u7684\u6e90\u4ee3\u7801\u3002 2. \u4f5c\u4e1a2: \u6253\u5370ASCII\u7801\u8868 \u8fdb\u5165\u56fe\u5f62\u6a21\u5f0f\uff0c\u8f93\u51fa\u7ea2\u7684ascii\u7801\u548c\u7eff\u7684\u76f8\u5e94\u5341\u516d\u8fdb\u5236\u7f16\u53f7\u3002 \u4e2a\u4eba\u611f\u89c9\u5148\u628a\u4f4d\u79fb\u5199\u51fa\u6765\u518d\u586b\u91cc\u9762\u7684\u8f93\u51fa\u6bd4\u8f83\u597d\u5f04\u3002 \u53ef\u4ee5\u53c2\u7167\u4ed6\u7684\u6570\u5b57\u7528\u5faa\u73af\u5de6\u79fb\u8f93\u51fa\u6210\u5341\u516d\u8fdb\u5236\u4ee3\u7801\u3002 3. \u4f5c\u4e1a3: \u7b80\u6613\u8ba1\u7b97\u5668 \u6574\u4f53\u601d\u8def\uff1a80386\u8bed\u6cd5\u5199\uff0c\u5185\u5bb9\u90fd\u5b58\u5728\u5185\u5b58\u53d8\u91cf\u91cc \u52a0\u6cd5\u601d\u8def\uff1a\u9ad8\u4f4d\u52a0\u9ad8\u4f4d\uff0c\u4f4e\u4f4d\u52a0\u4f4e\u4f4d \u4e58\u6cd5\u601d\u8def\uff1a\u5206\u522b\u4e58\u4f4e\u4f4d\u548c\u9ad8\u4f4d\uff0c\u9ad8\u4f4d\u7ed3\u679c\u52a0\u8fdb\u4f4d \u9664\u6cd5\u601d\u8def\uff1a\u5206\u522b\u9664\u9ad8\u4f4d\u548c\u4f4e\u4f4d\uff0c\u3002\u3002\u540e\u9762\u5fd8\u4e86 \u8f93\u51fa\u5341\u8fdb\u5236\u601d\u8def\uff1a\u9ad8\u4f4d\u4f4e\u4f4d \u8f93\u51fa\u5341\u516d\u8fdb\u5236\u601d\u8def\uff1a 4. \u4f5c\u4e1a4: C\u4ee3\u7801\u6587\u4ef6\u67e5\u770b\u5668\u7ffb\u8bd1\u6210\u6c47\u7f16 \u4ed6\u4f1a\u7ed9\u4e00\u4e2ac\u6e90\u4ee3\u7801\uff0c\u7528c\u548c\u6c47\u7f16\u5939\u5fc3\u8c03\u8bd5\u628ac\u7ffb\u8bd1\u6210\u6c47\u7f16\u3002 \u903b\u8f91\u7684\u601d\u8def\uff1a \u5bc4\u5b58\u5668\u72b6\u6001\u4fdd\u5b58+\u521d\u59cb\u72b6\u6001+\u5224\u65ad\u7ec8\u6b62+\u64cd\u4f5c+\u50a8\u5b58+\u5faa\u73af\u6761\u4ef6+\u8df3\u8f6c+\u5bc4\u5b58\u5668\u72b6\u6001\u6062\u590d
"},{"location":"CS/x86assm/#6","title":"6\u79cd\u5bfb\u5740\u65b9\u5f0f\u4e0e\u5176\u4f5c\u7528","text":"\u8bf4\u660e \u793a\u4f8b \u4f5c\u7528 \u7acb\u5373\u5bfb\u5740 mov eax,56H \u901a\u5e38\u7528\u4e8e\u8d4b\u503c \u76f4\u63a5\u5bfb\u5740 mov eax,[1255887H] \u901a\u5e38\u7528\u4e8e\u5904\u7406\u53d8\u91cf \u5bc4\u5b58\u5668\u5bfb\u5740 mov eax,[edi] \u5730\u5740\u5728\u5bc4\u5b58\u5668\u4e2d \u5bc4\u5b58\u5668\u76f8\u5bf9\u5bfb\u5740 mov eax,[edi+20H] \u5e38\u7528\u4e8e\u8bbf\u95ee\u6570\u7ec4\u548c\u7ed3\u6784 \u57fa\u5740\u52a0\u53d8\u5740\u5bfb\u5740 mov eax,[EBP+ESI] \u5e38\u7528\u4e8e\u8bbf\u95ee\u6570\u7ec4 \u76f8\u5bf9\u57fa\u5740\u52a0\u53d8\u5740\u5bfb\u5740 mov eax,[EBX+EDI-10H] \u5e38\u7528\u4e8e\u8bbf\u95ee\u7ed3\u6784"},{"location":"CS/x86assm/#obj-dump","title":"obj dump","text":"\u6e90\u4ee3\u7801\u6587\u4ef6\u540dmytest.c
gcc -c -g -o mytest mytest.c\nobjdump -s -d main.o > main.o.txt\n
\u76ee\u6807\u6587\u4ef6\u53cd\u6c47\u7f16\uff0c\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -c -o main.o main.c\nobjdump -S -d main.o > main.o.txt\n
\u663e\u793a\u6e90\u4ee3\u7801\u7684\u540c\u65f6\u663e\u793a\u884c\u53f7
objdump -j .text -ld -C -S main.o > main.o.txt\n
\u53ef\u6267\u884c\u6587\u4ef6\u53cd\u6c47\u7f16
gcc -o main main.c\nobjdump -s -d main > main.txt\n
\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -o main main.c\nobjdump -S -d main > main.txt\n
"},{"location":"CS/x86assm/#_1","title":"\u671f\u672b\u8003\u8bd5","text":"\u7a0b\u5e8f\u586b\u7a7a\u9898(3\u9898\uff0c\u6bcf\u989810\u5206\uff0c\u517130\u5206)
\u4e00\u822c\u90fd\u4f1a\u7528stack\u538b\u5165\u53c2\u6570 \u4f1a\u7ed9\u51fac\u8bed\u8a00\u7684\u539f\u578b\uff08\uff1f\uff0c\u53c2\u6570\u7684\u538b\u5165\u987a\u5e8f\u4ece\u53f3\u5230\u5de6\uff0ccaller\u6e05\u7406 pascal\uff0c\u4ece\u5de6\u5230\u53f3\uff0ccallee\u6e05\u7406 stdcall\uff0c\u4ece\u53f3\u5230\u5de6\uff0ccaller\u6e05\u7406 \u90fd\u7528ax\u8fd4\u56de\u53c2\u6570 \u4e00\u822c\u4e24\u4e2a\u7a7a\u4e0d\u53ef\u4ee5\u4ea4\u6362\u3002\u3002\u3002 \u5148\u81ea\u5df1\u5199\u4e00\u904d\u518d\u586b \uff08\u4e00\u822c20\u51e0\u884c\u7684\u7a0b\u5e8f\uff09
\u7a0b\u5e8f\u9605\u8bfb(2\u9898\uff0c\u6bcf\u98985\u5206\uff0c\u517110\u5206) \u4f1a\u95ee\u8fd0\u884c\u7ed3\u679c\u548c\u4e2d\u95f4\u7ed3\u679c\uff08#\uff09\uff08\u5982\u679c\u6709\u5faa\u73af\uff0c\u6bcf\u6b21\u5faa\u73af\u5230\u90fd\u8981\u5199\uff0c\u4f46\u662f\u4e0d\u4f1a\u592a\u591a\uff09
\u4e0d\u4f1a\u6709\u76f4\u63a5\u624b\u5199\u4e00\u6574\u4e2a\u7a0b\u5e8f\u7684\u9898
\u91cd\u70b9\uff1a \u51fd\u6570\u53c2\u6570\u4f20\u9012\uff0c\u5982\u4f55\u6784\u9020\u4e00\u4e2a\u5806\u6808\u6846\u67b6\uff0cebp\u3002\u3002 \u9700\u8981\u770b\u61c2\u662f\u4e0d\u662f\u9012\u5f52\uff0c \u6709\u4e00\u4e2a\u7a0b\u5e8f\u586b\u7a7a\u4f1a\u51fa\u5355\u6b65\u8c03\u8bd5\uff0c\u8fb9\u89e3\u5bc6\u8fb9\u52a0\u5bc6\u90a3\u4e2a\u3002\u3002 \u4e0d\u4f1a\u8003\u4fdd\u62a4\u6a21\u5f0f\u3002
"},{"location":"CS/x86assm/#_2","title":"\u590d\u4e60","text":""},{"location":"CS/x86assm/#intel-808680386-cpu","title":"Intel 8086/80386 CPU \u529f\u80fd\u7ed3\u6784","text":""},{"location":"CS/x86assm/#_3","title":"\u5de5\u4f5c\u65b9\u5f0f","text":"\u8fd0\u7b97\u5668\u8fdb\u884c\u4fe1\u606f\u5904\u7406\uff0c\u5bc4\u5b58\u5668\u8fdb\u884c\u4fe1\u606f\u5b58\u50a8\uff0c\u63a7\u5236\u5668\u63a7\u5236\u5404\u79cd\u5668\u4ef6\u5de5\u4f5c\uff0c\u603b\u7ebf\u8fde\u63a5\u5404\u79cd\u5668\u4ef6\u3002
"},{"location":"CS/x86assm/#163280x86-view","title":"16\u4f4d\u548c32\u4f4d\u768480x86\u7684\u533a\u522b - \u64cd\u4f5c\u7cfb\u7edfview","text":"1234h:0058h \u8f6c\u5316\u6210\u7269\u7406\u5730\u5740=12340h+0058h=12398h \u8865\u7801
"},{"location":"CS/x86assm/#_5","title":"\u6807\u5fd7\u4f4d","text":"\u72b6\u6001\u6807\u5fd7\uff1aCF ZF SF OF AF PF \u63a7\u5236\u6807\u5fd7\uff1aDF(direction flags) TF(trace/trap flag) IF(interrupt flag)
"},{"location":"CS/x86assm/#_6","title":"\u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u653e\u89c4\u5f8b\uff1a","text":"\u5c0f\u7aef\u683c\u5f0f\u3002\u4f4e\u5b57\u8282\u5728\u524d\uff0c\u9ad8\u5b57\u8282\u5728\u540e\u3002 \u8bbeds=1000h, bx=2000h, ax=1234h Mov ds:[bx], ax \u6267\u884c\u540e1000:2001\u6307\u5411\u7684\u5b57\u8282=12h
"},{"location":"CS/x86assm/#_7","title":"\u5bc4\u5b58\u5668","text":"\u603b\u7ed3
\u5bc4\u5b58\u5668 \u7c7b\u522b \u7528\u9014 AX \u6570\u636e\u5bc4\u5b58\u5668 \u7b97\u672f\u8fd0\u7b97\u4e2d\u7684\u4e3b\u8981\u5bc4\u5b58\u5668\uff0c\u5728\u4e58\u9664\u8fd0\u7b97\u4e2d\u7528\u6765\u5236\u5b9a\u88ab\u9664\u6570\uff0c\u4e5f\u662f\u4e58\u9664\u8fd0\u7b97\u540e\u7ed3\u679c\u7684\u9ed8\u8ba4\u5b58\u50a8\u5355\u5143\u3002\u53e6\u5916I/O\u6307\u4ee4\u5747\u4f7f\u7528\u8be5\u5bc4\u5b58\u5668\u4e0eI/O\u8bbe\u5907\u4f20\u9001\u4fe1\u606f\u3002 BX \u6570\u636e\u5bc4\u5b58\u5668 \u6307\u4ee4\u5bfb\u5740\u65f6\u5e38\u7528\u505a\u57fa\u5740\u5bc4\u5b58\u5668\uff0c\u5b58\u5165\u504f\u79fb\u91cf\u6216\u504f\u79fb\u91cf\u7684\u6784\u6210\u6210\u5206 CX \u6570\u636e\u5bc4\u5b58\u5668 \u5728\u5faa\u73af\u6307\u4ee4\u64cd\u4f5c\u6216\u4e32\u5904\u7406\u6307\u4ee4\u4e2d\u9690\u542b\u8ba1\u6570 DX \u6570\u636e\u5bc4\u5b58\u5668 \u5728\u53cc\u5b57\u8282\u957f\u8fd0\u7b97\u4e2d\u4e0eAX\u6784\u621032\u4f4d\u64cd\u4f5c\u6570\uff0cDX\u4e3a\u9ad816\u4f4d\u3002\u5728\u67d0\u4e9bI/O\u6307\u4ee4\u4e2d\uff0cDX\u88ab\u7528\u6765\u5b58\u653e\u7aef\u53e3\u5730\u5740 SP \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u59cb\u7ec8\u662f\u6808\u9876\u7684\u4f4d\u7f6e\uff0c\u4e0eSS\u5bc4\u5b58\u5668\u4e00\u8d77\u6784\u6210\u6808\u9876\u6570\u636e\u7684\u7269\u7406\u5730\u5740 BP \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u7cfb\u7edf\u9ed8\u8ba4\u5176\u6307\u5411\u5806\u6808\u4e2d\u67d0\u4e00\u5355\u5143\uff0c\u5373\u63d0\u4f9b\u6808\u4e2d\u8be5\u5355\u5143\u7684\u504f\u79fb\u91cf\u3002\u52a0\u6bb5\u524d\u7f00\u540e\uff0cBP\u53ef\u4f5c\u4e3a\u975e\u5806\u6808\u6bb5\u7684\u5730\u5740\u6307\u9488 SI \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u4e0eDS\u8054\u7528\uff0c\u6307\u793a\u6570\u636e\u6bb5\u4e2d\u67d0\u64cd\u4f5c\u7684\u504f\u79fb\u91cf\u3002\u5728\u505a\u4e32\u5904\u7406\u65f6\uff0cSI\u6307\u793a\u6e90\u64cd\u4f5c\u6570\u5730\u5740\uff0c\u5e76\u6709\u81ea\u52a8\u589e\u91cf\u548c\u81ea\u52a8\u51cf\u91cf\u7684\u529f\u80fd\u3002\u53d8\u5740\u5bfb\u5740\u65f6\uff0cSI\u4e0e\u67d0\u4e00\u4f4d\u79fb\u91cf\u5171\u540c\u6784\u6210\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf DI \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u4e0eDS\u8054\u7528\uff0c\u6307\u793a\u6570\u636e\u6bb5\u4e2d\u67d0\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf\uff0c\u6216\u4e0e\u67d0\u4e00\u4f4d\u79fb\u91cf\u5171\u540c\u6784\u6210\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf\uff0c\u4e32\u5904\u7406\u64cd\u4f5c\u65f6\uff0cDI\u6307\u793a\u9644\u52a0\u6bb5\u4e2d\u76ee\u7684\u5730\u5740\uff0c\u5e76\u6709\u81ea\u52a8\u589e\u91cf\u548c\u51cf\u91cf\u7684\u529f\u80fd\u3002 CS \u6bb5\u5bc4\u5b58\u5668 \u5b58\u653e\u5f53\u524d\u7a0b\u5e8f\u7684\u6307\u793a\u4ee3\u7801 DS \u6bb5\u5bc4\u5b58\u5668 \u5b58\u653e\u7a0b\u5e8f\u6240\u8bbe\u8ba1\u7684\u6e90\u6570\u636e\u6216\u7ed3\u679c SS \u6bb5\u5bc4\u5b58\u5668 \u4ee5\u201c\u5148\u5165\u540e\u51fa\u201d\u4e3a\u539f\u5219\u7684\u6570\u636e\u533a ES \u6bb5\u5bc4\u5b58\u5668 \u8f85\u52a9\u6570\u636e\u533a\uff0c\u5b58\u653e\u4e32\u6216\u5176\u5b83\u6570\u636e IP \u63a7\u5236\u5bc4\u5b58\u5668 \u5b83\u59cb\u7ec8\u6307\u5411\u5f53\u524d\u5c06\u8981\u6267\u884c\u6307\u4ee4\u5728\u4ee3\u7801\u6bb5\u4e2d\u7684\u504f\u79fb\u91cf FR \u63a7\u5236\u5bc4\u5b58\u5668 \u63a7\u5236\u6807\u5fd7\u4f4d "},{"location":"CS/x86assm/#_8","title":"\u901a\u7528\u5bc4\u5b58\u5668","text":"IA-32\u67b6\u6784\u4e2d\u4e00\u5171\u67094\u4e2a32\u4f4d\u5bc4\u5b58\u5668\uff0c\u7528\u4e8e\u4fdd\u5b58\u4e34\u65f6\u6570\u636e\uff0c\u8fd94\u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u53ef\u4ee5\u5f53\u4f5c16\u4f4d\u7528\uff0c\u4e5f\u53ef\u4ee5\u4f5c8\u4f4d\u7528\u3002
AX BX CX DX\uff1a\u6570\u636e\u5bc4\u5b58\u5668\uff0c\u6bcf\u4e2a\u6570\u636e\u5bc4\u5b58\u5668\u90fd\u53ef\u4ee5\u62c6\u6210\u4e24\u4e2a 8 \u4f4d\u5bc4\u5b58\u5668\u72ec\u7acb\u4f7f\u7528\uff0c\u5982 AX \u53ef\u62c6\u5206\u4e3a AH \u548c AL\uff0cBX \u62c6\u5206\u4e3a BH \u548c BL \u7b49\u3002H \u548c L \u5206\u522b\u8868\u793a\u9ad8 8 \u4f4d\u548c\u4f4e 8 \u4f4d\u3002
AX(accumulator)\uff1a\u7d2f\u52a0\u5668\u3002\u5728\u4e58\u9664\u6cd5\u8fd0\u7b97\u3001\u4e32\u8fd0\u7b97\u3001 I/O \u6307\u4ee4\u4e2d\u90fd\u4f5c\u4e3a\u4e13\u7528\u5bc4\u5b58\u5668\uff1b BX (base)\uff1a\u57fa\u5740\u5bc4\u5b58\u5668\uff0c\u5e38\u7528\u4e8e\u5b58\u6863\u5185\u5b58\u5730\u5740\u3002
CX (count)\uff1a\u8ba1\u6570\u5bc4\u5b58\u5668\u3002\u5e38\u7528\u4e8e\u5b58\u653e\u5faa\u73af\u8bed\u53e5\u7684\u5faa\u73af\u6b21\u6570\uff0c\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u4e5f\u5e38\u7528\u3002
DX (data)\uff1a\u6570\u636e\u5bc4\u5b58\u5668\u3002\u5e38\u5e38\u548cEAX\u4e00\u8d77\u4f7f\u7528\u3002
"},{"location":"CS/x86assm/#_9","title":"\u53d8\u5740\u5bc4\u5b58\u5668","text":"\u5b58\u653e\u5728\u53d8\u52a8\u7684\u5185\u5b58\u5730\u5740
ESI(source index): \u6e90\u53d8\u5740\u5bc4\u5b58\u5668\uff0c\u901a\u5e38\u5b58\u653e\u8981\u5904\u7406\u7684\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u3002
EDI(destination index)\uff1a\u76ee\u7684\u53d8\u5740\u5bc4\u5b58\u5668\uff0c\u901a\u5e38\u5b58\u653e\u5904\u7406\u540e\u7684\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u3002
ESI\u548cEDI\u5e38\u7528\u6765\u914d\u5408\u4f7f\u7528\u5b8c\u6210\u6570\u636e\u7684\u8d4b\u503c\u64cd\u4f5c
rep movs dword ptr[edi], dword ptr[esi];\n
\u8fd9\u53e5\u7684\u610f\u601d\u662f\u628aESI\u6307\u5411\u7684\u5185\u5b58\u5730\u5740\u4e2d\u7684\u5185\u5bb9\u590d\u5236\u5230EDI\u6240\u6307\u5411\u7684\u5185\u5b58\u4e2d\uff0c\u6570\u636e\u957f\u5ea6\u5728ECX\u4e2d\u6307\u5b9a\u3002
"},{"location":"CS/x86assm/#_10","title":"\u6307\u9488\u5bc4\u5b58\u5668","text":"ESP\uff08stack pointer\uff09\uff1a\u5806\u6808\u6307\u9488\u5bc4\u5b58\u5668\u3002SS\uff1aSP\u6307\u5411\u5806\u6808\u7684\u6808\u9876\uff0c\u56e0\u6b64\u867d\u7136\u662f\u901a\u7528\u5bc4\u5b58\u5668\uff0c\u4f46\u4e0d\u5e94\u968f\u4fbf\u6539\u53d8SP\u7684\u503c\u3002\u4e0d\u53ef\u4ee5\u4f5c\u4e3a\u901a\u7528\u5bc4\u5b58\u5668\u4f7f\u7528\uff0cESP\u5b58\u653e\u5f53\u524d\u5806\u6808\u6808\u9876\u7684\u5730\u5740\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cESP\u548cEBP\u8054\u5408\u4f7f\u7528\u6765\u8bbf\u95ee\u51fd\u6570\u4e2d\u7684\u53c2\u6570\u548c\u5c40\u90e8\u53d8\u91cf\u3002 EBP\uff08base pointer\uff09\uff1a\u57fa\u5740\u6307\u9488\u5bc4\u5b58\u5668\u3002\u53ef\u4ee5\u4f5c\u4e3a\u901a\u7528\u5bc4\u5b58\u5668\u7528\u4e8e\u5b58\u653e\u64cd\u4f5c\u6570\uff0c\u5e38\u7528\u6765\u4ee3\u66ff\u5806\u6808\u6307\u9488\u8bbf\u95ee\u5806\u6808\u7684\u6570\u636e\u3002 EIP\uff1a\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668\uff0c\u603b\u662f\u6307\u5411\u4e0b\u4e00\u6761\u8981\u6267\u884c\u7684\u6307\u4ee4\u7684\u5730\u5740\u3002 \u5e38\u89c1\u7684\u8bbf\u95ee\u5806\u6808\u6307\u4ee4\uff1a
push ebp\nmov ebp, esp\nsub esp, 78\npush esi\npush edi\ncmp dword ptr [ebp+8], 0\n
ss\u6808\u6bb5\u5bc4\u5b58\u5668 sp\u6808\u9876\u6307\u9488\u5bc4\u5b58\u5668 bp\u9ed8\u8ba4\u7684\u6808\u5bfb\u5740\u5bc4\u5b58\u5668
"},{"location":"CS/x86assm/#_11","title":"\u6807\u5fd7\u5bc4\u5b58\u5668","text":"\u6807\u5fd7\u5bc4\u5b58\u5668EFLAGS\u4e00\u5171\u670932\u4f4d\uff0c\u5728\u8fd932\u4f4d\u4e2d\u5927\u90e8\u5206\u662f\u4fdd\u7559\u7ed9\u7f16\u5199\u64cd\u4f5c\u7cfb\u7edf\u7684\u4eba\u7528\u7684\u3002
IP (instruction pointer)\uff1a\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668\u3002\u4ee3\u7801\u6bb5\u5bc4\u5b58\u5668 CS \u548c\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668 IP \u662f 8086CPU \u4e2d\u6700\u5173\u952e\u7684\u4e24\u4e2a\u5bc4\u5b58\u5668\u3002\u5b83\u4eec\u5206\u522b\u7528\u6765\u63d0\u4f9b\u5f53\u524d\u6307\u4ee4\u7684\u6bb5\u5730\u5740\u548c\u504f\u79fb\u5730\u5740\u3002\u5373\u4efb\u610f\u65f6\u523b\uff0c8086CPU \u5c06 CS:IP \u6307\u5411\u7684\u5185\u5bb9\u5f53\u505a\u547d\u4ee4\u6267\u884c\u3002\u6bcf\u6761\u6307\u4ee4\u8fdb\u5165\u6307\u4ee4\u7f13\u51b2\u5668\u540e\u3001\u6267\u884c\u524d\uff0cIP += \u6240\u8bfb\u53d6\u6307\u4ee4\u7684\u957f\u5ea6\uff0c\u4ece\u800c\u6307\u5411\u4e0b\u4e00\u6761\u6307\u4ee4\u3002\u7528\u6237\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee IP \u5bc4\u5b58\u5668\u3002
FL (flags)\uff1a\u6807\u5fd7\u5bc4\u5b58\u5668\u3002\u4e0e\u5176\u4ed6\u5bc4\u5b58\u5668\u4e00\u6837\uff0c\u6807\u5fd7\u5bc4\u5b58\u5668\u4e5f\u6709 16 \u4f4d\uff0c\u4f46\u662f\u6807\u5fd7\u5bc4\u5b58\u5668\u53ea\u7528\u5230\u5176\u4e2d\u7684 9 \u4f4d\u3002\u8fd9 9 \u4f4d\u5305\u62ec 6 \u4e2a\u72b6\u6001\u6807\u5fd7\u548c 3 \u4e2a\u63a7\u5236\u6807\u5fd7\uff0c\u53c2\u89c1\u4e0b\u9762\u7684\u201c\u6807\u5fd7\u4f4d\u201d\u3002
OF\uff08Overflow Flag\uff09:\u6ea2\u51fa\u6807\u5fd7\uff0c\u6ea2\u51fa\u65f6\u4e3a1\uff0c\u5426\u5219\u7f6e0\u3002\u4e24\u4e2a\u6b63\u6570\u76f8\u52a0\u53d8\u8d1f\uff0c\u6216\u4e24\u4e2a\u8d1f\u6570\u76f8\u52a0\u53d8\u6b63\u4f1a\u6ea2\u51fa\u3002#
DF \uff08Direction Flag\uff09:\u65b9\u5411\u6807\u5fd7\uff0c\u5728\u4e32\u5904\u7406\u6307\u4ee4\u4e2d\u63a7\u5236\u4fe1\u606f\u7684\u65b9\u5411\u30020:\u6b63\u65b9\u5411\uff0c1\uff1a\u53cd\u65b9\u5411\u3002cld\uff0cstd\u3002#
IF (Interrupt Flag) :\u4e2d\u65ad\u6807\u5fd7\u3002\u7981\u6b62\u4e2d\u65ad0\uff0c\u5141\u8bb8\u4e2d\u65ad1\u3002cli\uff0csti\u3002#
AF (Auxiliary carry Flag) :\u8f85\u52a9\u8fdb\u4f4d\u6807\u5fd7\uff0c\u6709\u8fdb\u4f4d\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
ZF (Zero Flag) :\u96f6\u6807\u5fd7\uff0c\u8fd0\u7b97\u7ed3\u6784\u4e3a0\u65f6ZF\u4f4d\u4f4d\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
SF (Sign Flag):\u7b26\u53f7\u6807\u5fd7\uff0c\u7ed3\u679c\u4e3a\u8d1f\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002#
CF (Carry Flag): \u8fdb\u4f4d\u6807\u5fd7\uff0c\u8fdb\u4f4d\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002\u914d\u5957\u7684clc\uff0cstc\u4e24\u6761\u8bbe\u7f6e\u6307\u4ee4\uff1a\u6e05\u9664\u548c\u7f6e1\u3002#
PF (Parity Flag): \u5947\u5076\u6807\u5fd7\u3002\u7ed3\u679c\u64cd\u4f5c\u6570\u4e2d1\u7684\u4e2a\u6570\u4e3a\u5076\u6570\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
TF\uff1a\u5355\u6b65\u8c03\u8bd5\u8981\u7528\u3002#
EFLAGS\u662f\u5b9e\u73b0\u6761\u4ef6\u5224\u65ad\u548c\u903b\u8f91\u5224\u65ad\u7684\u4e00\u79cd\u673a\u5236\uff0c\u5728\u6c47\u7f16\u8bed\u8a00\u4e2d\u4e00\u822c\u4e0d\u76f4\u63a5\u8bbf\u95eeEFLAGS\u5bc4\u5b58\u5668\uff0c\u800c\u662f\u901a\u8fc7\u6307\u4ee4\u7684\u64cd\u4f5c\u9690\u542b\u8bbf\u95eeEFLAGS\u5bc4\u5b58\u5668\u3002
cmp dword ptr [ebp+8], 0. // \u5f71\u54cd\u6807\u5fd7\u4f4dCF\uff0cZF\uff0cSF\uff0cOF\uff0cAF\u548cPF\nJz 99495898 //\u5982\u679cZF\u7b49\u4e8e1\uff0c\u5219\u8df3\u8f6c\u523000405898
"},{"location":"CS/x86assm/#_12","title":"\u6307\u4ee4","text":"\u603b\u7ed3
\u6307\u4ee4 \u4f5c\u7528 \u53c2\u6570 \u6539\u53d8\u6807\u5fd7\u4f4d mov \u8d4b\u503c \u88ab\u8d4b\u503c\u5bc4\u5b58\u5668\uff0c\u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\uff0c\u503c\u3011 no xchg \u6570\u636e\u4ea4\u6362 \u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\u3011\uff0c\u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\u3011 no push \u8fdb\u6808 \u6e90\u64cd\u4f5c\u6570\u3010\u5bc4\u5b58\u5668\u3011 pop \u51fa\u6808 \u76ee\u7684\u64cd\u4f5c\u6570\u3010\u5bc4\u5b58\u5668\u3011 pushf \u6807\u5fd7\u4f4d\u8fdb\u6808 \u65e0 popf \u6807\u5fd7\u4f4d\u51fa\u6808 \u65e0 lea Load effect address\uff0c\u5bfb\u5740\uff0c\u53d6\u504f\u79fb\u5730\u5740 lds \u5f53\u6307\u4ee4\u6307\u5b9a\u7684\u662f16\u4f4d\u5bc4\u5b58\u5668\u65f6\uff0c\u628a\u6e90\u64cd\u4f5c\u6570\u5b58\u50a8\u5355\u5143\u4e2d\u5b58\u653e\u7684\u5341\u516d\u4f4d\u504f\u79fb\u5730\u5740\u53d6\u51fa\u5b58\u653e\u5728\u5bc4\u5b58\u5668\u4e2d\uff0c\u7136\u540e\u628a\u6e90\u64cd\u4f5c\u6570+2\u7684\u5341\u516d\u4f4d\u6570\u88c5\u5165\u6307\u4ee4\u6307\u5b9a\u7684\u6bb5\u5bc4\u5b58\u5668\u3002\u5f53\u6307\u4ee4\u6307\u5b9a\u7684\u662f32\u4f4d\u5bc4\u5b58\u5668\u65f6 \u628a\u6e90\u64cd\u4f5c\u6570\u5b58\u50a8\u5355\u5143\u4e2d\u5b58\u653e\u768432\u4f4d\u504f\u79fb\u5730\u5740\u88c5\u5165\u5bc4\u5b58\u5668 \u7136\u540e\u628a \u6e90\u64cd\u4f5c\u6570+4 \u768416\u4f4d\u6570\u88c5\u5165\u6bb5\u5bc4\u5b58\u5668\u3002mem\u6307\u5411\u7684\u5730\u5740,\u9ad8\u4f4d\u5b58\u653e\u5728DS\u4e2d,\u4f4e\u4f4d\u5b58\u653e\u5728reg\u4e2d. LDS reg,mem les \u628a\u5185\u5b58\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u7684\u53cc\u5b57\u64cd\u4f5c\u6570\u7684\u4f4e\u4f4d\u5b57\u88c5\u5165\u6307\u4ee4\u4e2d\u6307\u5b9a\u7684\u5bc4\u5b58\u5668\u3001\u9ad8\u4f4d\u5b57\u88c5\u5165ES\u5bc4\u5b58\u5668\u3002 cbw 8\u4f4d\u6570\u6269\u5c55\u4e3a16\u4f4d\u6570\uff0c\u6709\u7b26\u53f7\u6269\u5145 no cwd \u5b57(16\u4f4d)\u6269\u5c55\u4e3a\u53cc\u5b57(32\u4f4d)\uff0c\u6709\u7b26\u53f7\uff1f no add \u52a0 OPRDS\uff0cOPRDD adc \u5e26\u8fdb\u4f4d\u52a0\uff08\u7ed3\u679c\u542b\u6807\u5fd7\u4f4dCF\u7684\u503c\uff0c=OPRDS\uff0bOPRDD\uff0bCF\uff09 OPRDS\uff0cOPRDD sub \u51cf OPRDD\uff0cOPRDS sbb \u5e26\u8fdb\u4f4d\u51cf\uff08\u7ed3\u679c\u542b\u6807\u5fd7\u4f4dCF\u7684\u503c\uff0c=OPRDD\uff0dOPRDS\uff0dCF\uff09 OPRDD\uff0cOPRDS inc \u81ea\u589e1 \u5bc4\u5b58\u5668 dec \u81ea\u51cf1 \u5bc4\u5b58\u5668 mul 32\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aEAX\uff0c\u90a3\u4e48\u4e58\u79ef\u5c06\u5b58\u653e\u5728EDX\uff1aEAX\u4e2d 32\u4f4d\u4e58\u6570 16\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aAX\u90a3\u4e48\u4e58\u79ef\u5c06\u653e\u5728DX\uff1aAX\u4e2di 16\u4f4d\u4e58\u6570 8\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aAL\uff0c\u90a3\u4e48\u4e58\u79ef\u5c06\u653e\u5728AX 8\u4f4d\u4e58\u6570 div 32\u4f4d\uff1a\u88ab\u9664\u6570\u5c06\u662fEDX\uff1aEAX\uff0c \u6700\u7ec8\u7684\u5546\u5c06\u5b58\u653e\u5728EAX\uff0c \u4f59\u6570\u5c06\u5b58\u653e\u5728EDX\u4e2d 32\u4f4d\u4e58\u6570 16\u4f4d\uff1a\u88ab\u9664\u6570\u4e3aEAX\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u5546\u653e\u5728AX\uff0c\u4f59\u6570\u653e\u5728EAX\u7684\u9ad816\u4f4d 16\u4f4d\u4e58\u6570 8\u4f4d\uff1a\u88ab\u9664\u6570\u662f16\u4f4d\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u5546\u5c06\u653e\u5728AL\u4e2d\uff0c\u4f59\u6570\u653e\u5728AH\u4e2d 8\u4f4d\u4e58\u6570 imul \u65e0\u7b26\u53f7\u4e58 idiv \u65e0\u7b26\u53f7\u9664 xlat \u6362\u7801\u6307\u4ee4\uff0c\u4ee5bx\u4e3a\u9996\u5730\u5740\u7684\uff0c\u504f\u79fb\u5730\u5740\u4e3aal\u7684\u5185\u5bb9\u9001\u7ed9al\u3002 in \u7aef\u53e3\u8bfb\u5199\u6307\u4ee4 IN AL,21H\uff1b\u8868\u793a\u4ece21H\u7aef\u53e3\u8bfb\u53d6\u4e00\u5b57\u8282\u6570\u636e\u5230AL out \u7aef\u53e3\u8bfb\u5199\u6307\u4ee4 and \u6309\u4f4d\u4e0e or \u6309\u4f4d\u6216 xor \u6309\u4f4d\u5f02\u6216 not \u64cd\u4f5c\u6570\u6309\u4f4d\u53d6\u53cd neg \u64cd\u4f5c\u6570\u6309\u4f4d\u53d6\u53cd\u52a0\u4e00 test \u5bf9\u4e24\u4e2a\u64cd\u4f5c\u6570\u8fdb\u884c\u6309\u4f4d\u4e0e\u64cd\u4f5c\u3002\u4e0eand\u4e0d\u540c\uff0c\u4e0d\u5f71\u54cd\u76ee\u6807\u64cd\u4f5c\u6570\u7684\u503c\u3002 shl \u903b\u8f91\u5de6\u79fb\uff0c\u5c06\u4e00\u4e2a\u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u6216\u5355\u5143\u4e2d\u7684\u6570\u636e\u5411\u5de6\u79fb\u4f4d\uff0c\u5c06\u6700\u540e\u79fb\u51fa\u7684\u4e00\u4f4d\u5199\u5165cf\u4e2d\u3002\u6700\u4f4e\u4f4d\u75280\u8865\u5145\u3002 shr \u903b\u8f91\u53f3\u79fb\uff0c\u5c06\u4e00\u4e2a\u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u6216\u5355\u5143\u4e2d\u7684\u6570\u636e\u5411\u5de6\u79fb\u4f4d\uff0c\u5c06\u6700\u540e\u79fb\u51fa\u7684\u4e00\u4f4d\u5199\u5165cf\u4e2d\u3002\u6700\u9ad8\u4f4d\u75280\u8865\u5145\u3002 sal \u7b97\u672f\u5de6\u79fb\uff0c\u4e0eshl\u4e00\u6837\uff0c\u88650 sar \u7b97\u672f\u53f3\u79fb\uff0c\u4e0eshr\u4e0d\u4e00\u6837\uff0c\u7b97\u672f\u53f3\u79fb\u8865\u6700\u9ad8\u4f4d rol \u5faa\u73af\u5de6\u79fb ror \u5faa\u73af\u53f3\u79fb rcl \u5e26\u8fdb\u4f4d\u5faa\u73af\u5de6\u79fb\uff0c\u5de6\u79fb\u7684\u65f6\u5019\u79fb\u51fa\u53bb\u7684\u4f1a\u653e\u5728cf\uff1f rcr \u5e26\u8fdb\u4f4d\u5faa\u73af\u53f3\u79fb cmp \u6bd4\u8f83 ja jump if above jb Jump if below jae Jump if above or equal jbe Jump if below or equal jg jump if greater\uff0c\u6709\u7b26\u53f7\u5927\u4e8e\u8df3\u8f6c jl jump less\uff0c\u6709\u7b26\u53f7\u5c0f\u4e8e\u8df3\u8f6c jge jump if greater or equal jle Jump if less or equal jc jump if with carry, CF = 1 jnc jump if not with carry, CF = 0 je = jz jump if equal, ZF = 1 jne = jnz jump if not equal, ZF = 0 jz jump if zero, ZF = 1 jnz jump if not zero, ZF = 0 jcxz jump if cx equals zero js SF = 1 jns SF = 0 jo Jump if overflow, OF = 1 jno jump if not overflow, OF = 0 loop \u5faa\u73af \u4ee3\u7801\u6bb5\uff08\uff1f\uff09\u540d clc clear carry flag\uff0c\u5c06cf\u4f4d\u6e05\u96f6 stc set carry flag\uff0cCF\u7f6e1 cli clear interrupt endable flag\uff0cIF\u6e05\u96f6\uff0c\u5173\u95ed\u4e2d\u65ad sti set interrupt endable flag\uff0cIF\u7f6e\u4f4d1\uff0c\u6253\u5f00\u4e2d\u65ad CMC complement carry flag\uff0cCF\u53d6\u53cd CLD clear direction flag\uff0cDF\u6e05\u96f6 STD set interrupt endable flag\uff0cDF\u7f6e1 call \u8fd1\u8c03\u7528 ret \u8fd1\u8fd4\u56de call far ptr \u8fdc\u8c03\u7528\u3002\u4e09\u4e2apush\u4e00\u4e2ajmp\u3002push f\uff0cpush cs\uff0cpush ip\uff0cjump retf \u8fdc\u8fd4\u56de\u3002\u4e09\u4e2apop\u3002\u6307\u4ee4\u2f64\u6808\u4e2d\u7684\u6570\u636e\uff0c\u4fee\u6539CS\u548cIP\u7684\u5185\u5bb9\uff0c\u4ece\u2f7d\u5b9e\u73b0\u8fdc\u8f6c\u79fb int \u4e2d\u65ad\u6307\u4ee4 iret \u4e2d\u65ad\u8fd4\u56de jmp short \u6bb5\u5185\u77ed\u8f6c\u79fb\uff0c\u77ed\u662f\u6307\u8981\u8df3\u2f84\u7684\u2f6c\u6807\u5730\u5740\u4e0e\u5f53\u524d\u5730\u5740\u524d\u540e\u76f8\u5dee\u4e0d\u8d85\u8fc7128\u5b57\u8282 jmp near ptr \u6bb5\u5185\u8fd1\u8f6c\u79fb\u3002\u8fd1\u662f\u6307\u8df3\u8f6c\u7684\u2f6c\u6807\u5730\u5740\u4e0e\u5f53\u524d\u5730\u5740\u5728\u2f64\u2f00\u4e2a\u6bb5\u5185\uff0c\u5373CS\u7684\u503c\u4e0d\u53d8\uff0c\u53ea\u6539\u53d8EIP\u7684\u503c jmp far ptr \u6bb5\u95f4\u8f6c\u79fb\uff0c\u8fdc\u6307\u8df3\u5230\u53e6\u2f00\u4e2a\u4ee3\u7801\u6bb5\u53bb\u6267\u2f8f\uff0cCS/EIP\u90fd\u8981\u6539\u53d8 Jmp dword ptr \u6bb5\u95f4\u8f6c\u79fb\uff0c\u4ee5\u5185\u5b58\u5730\u5740\u5355\u5143\u5904\u7684\u53cc\u5b57\u6765\u4fee\u6539\u6307\u4ee4\uff0c\u2fbc\u5730\u5740\u5185\u5bb9\u4fee\u6539CS\uff0c\u4f4e\u5730\u5740\u5185\u5bb9 \u4fee\u6539IP\uff0c\u5185\u5b58\u5730\u5740\u53ef\u4ee5\u4ee5\u4efb\u4f55\u5408\u6cd5\u7684\u2f45\u5f0f\u7ed9\u51fa repe/renpe scasb \u5b57\u7b26\u4e32\u626b\u63cf\u6307\u4ee4\u3002cmp al, es:[di] di++; \u5f53DF=1\u65f6\uff0c\u4e3adi-- repne:\u5f53ECX!=0\u5e76\u4e14ZF==0\u65f6 \u91cd\u590d repe: cx != 0\u4e14zf != 0\u91cd\u590d repe/renpe cmpsb \u5b57\u7b26\u4e32\u6bd4\u8f83\u6307\u4ee4\u3002\u2f50\u8f83byte ptr ds:[si]\u4e0ebyte ptr es:[di] \u5f53DF=0\u65f6\uff0cSI++\uff0cDI++ \u5f53DF=1\u65f6\uff0cSI--\uff0cDI-- repne:\u5f53ECX!=0\u5e76\u4e14ZF==0\u65f6 \u91cd\u590d repe: cx != 0\u4e14zf != 0\u91cd\u590d rep movsb \u5b57\u7b26\u4e32\u79fb\u52a8\u6307\u4ee4\u3002\u5176\u4e2drep\u8868\u793arepeat\uff0cs\u8868\u793astring\uff0cb\u8868\u793abyte \u5728\u6267\u2f8f\u6b64\u6307\u4ee4\u524d\u8981\u505a\u4ee5\u4e0b\u51c6\u5907\u2f2f\u4f5c\uff1a \u2460ds:si lodsb \u5757\u88c5\u5165\u6307\u4ee4\uff0c\u628aSI\u6307\u5411\u7684\u5b58\u50a8\u5355\u5143\u8bfb\u5165\u7d2f\u52a0\u5668\uff0clodsb\u5c31\u8bfb\u5165ax\uff0clodsw\u5c31\u8bfb\u5165ax\uff0c\u7136\u540esi\u81ea\u52a8\u589e\u52a0\u6216\u51cf\u5c0f1\u62162 stosb/stosw/stosd SI\u6307\u5411\u7684https://baike.baidu.com/item/%E5%AD%98%E5%82%A8%E5%8D%95%E5%85%83\u8bfb\u5165https://baike.baidu.com/item/%E7%B4%AF%E5%8A%A0%E5%99%A8,\u5176\u4e2dLODSB\u662f\u8bfb\u5165AL, LODSW\u662f\u8bfb\u5165AX\u4e2d, \u7136\u540eSI\u81ea\u52a8\u589e\u52a0\u6216\u51cf\u5c0f1\u62162\u4f4d.\u5f53\u65b9\u5411\u6807\u5fd7\u4f4dDF=0\u65f6\uff0c\u5219SI\u81ea\u52a8\u589e\u52a0\uff1bDF=1\u65f6\uff0cSI\u81ea\u52a8\u51cf\u5c0f\u3002 rep stosb lodsb"},{"location":"CS/x86assm/#_13","title":"\u6570\u636e\u4f20\u9001\u6307\u4ee4","text":"\u6570\u636e\u4f20\u9001\u6307\u4ee4\u662f\u4e3a\u4e86\u5b9e\u73b0CPU\u548c\u5185\u5b58\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u7aef\u53e3\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9001\u3002
mov
mov eax, 56 // \u5c0656H\u4f20\u9001\u5230eax\u5bc4\u5b58\u5668\nmov esi, dword ptr [eax * 2 + 1] // \u5c06\u5185\u5b58\u5730\u5740\u4e3aeax*2+1\u76844\u5b57\u8282\u6570\u636e\u4f20\u9001\u5230esi\u5bc4\u5b58\u5668\nmov ah, byte ptr [esi * 2 + eax] // \u5c06\u5185\u5b58\u5730\u5740\u4e3aesi*+eax\u5904\u76848\u4f4d\u6570\u636e\u4f20\u9001\u5230AH\u5bc4\u5b58\u5668\n
xchg
\u5bc4\u5b58\u5668\u548c\u5185\u5b58\u7684\u6570\u636e\u4ea4\u6362\uff0c\u4ea4\u6362\u7684\u6570\u636e\u53ef\u4ee5\u662f8\u5b57\u8282\u300116\u5b57\u8282\u621632\u5b57\u8282\uff0c\u5fc5\u987b\u683c\u5f0f\u76f8\u540c
xchg eax, edx; // \u5c06edx\u5bc4\u5b58\u5668\u7684\u503c\u548ceax\u5bc4\u5b58\u5668\u7684\u503c\u4ea4\u6362\nxchg [esp-55], edi; // \u5c06edi\u5bc4\u5b58\u5668\u7684\u503c\u548c\u5806\u6808\u5730\u5740\u4e3a[esp-55]\u5904\u7684\u503c\u4ea4\u6362\n
push pop
push\u548cpop\uff1a\u79f0\u4e3a\u538b\u5165\u5806\u6808\u6307\u4ee4\u548c\u5f39\u51fa\u5806\u6808\u6307\u4ee4\uff0c\u683c\u5f0f\u662fpush src(\u6e90\u64cd\u4f5c\u6570)\u548cpop dst(\u76ee\u7684\u64cd\u4f5c\u6570)\uff0cpush\u6307\u4ee4\u548cpop\u6307\u4ee4\u9700\u8981\u5339\u914d\u51fa\u73b0\uff0c\u5426\u5219\u5806\u6808\u4f1a\u4e0d\u5e73\u8861\u3002push\u6307\u4ee4\u5c06\u539f\u64cd\u4f5c\u6570src\u538b\u5165\u5806\u6808\uff0c\u540c\u65f6esp-4\uff08\u6808\u9876\u6307\u9488\u51cf\u4e00\u4e2a4\u4f4d\uff09\uff0c\u800cpop\u53cd\u4e4b\uff0c\u4ece\u5806\u6808\u7684\u9876\u90e8\u5f39\u51fa4\u5b57\u8282\u7684\u6570\u503c\u7136\u540e\u653e\u5165dst\u3002\u572832\u4f4d\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0cpush\u548cpop\u7684\u64cd\u4f5c\u662f\u4ee54\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\uff0cpush\u548cpop\u6307\u4ee4\u5e38\u7528\u4e8e\u5411\u51fd\u6570\u4f20\u53c2\u3002
push eax // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u4ee54\u5b57\u8282\u538b\u5165\u5806\u6808\uff0c\u540c\u65f6esp-4\npush dword ptr [12FF8589] // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230\u5185\u5b58\u5730\u5740\u4e3a12FF8589\u6240\u6307\u5730\u65b9\uff0c\u540c\u65f6esp+4\n-----------------------------------------------------------------------------\npop dword ptr [12FF8589] // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230\u5185\u5b58\u5730\u5740\u4e3a12FF8589\u6240\u6307\u7684\u5730\u65b9\uff0c\u540c\u65f6esp+4\npop eax // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230eax\u5bc4\u5b58\u5668\uff0c\u540c\u65f6esp+4\n
"},{"location":"CS/x86assm/#_14","title":"\u5730\u5740\u4f20\u9001\u6307\u4ee4","text":"x86\u67093\u6761\u5730\u5740\u4f20\u9001\u6307\u4ee4\uff0c\u5206\u522b\u662fLEA\uff0cLDS\u548cLES\u3002\u5176\u5b9eLDS\u548cLES\u6307\u4ee4\u548c\u6bb5\u5bc4\u5b58\u5668\u6709\u5173\uff0c\u572832\u4f4d\u7684windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u4e00\u822c\u7684\u7a0b\u5e8f\u5458\u90fd\u4e0d\u9700\u8981\u7ba1\u7406\u6bb5\u5bc4\u5b58\u5668\uff0c\u6240\u4ee5\u76f8\u5bf9\u800c\u8a00\uff0cLDS\u548cLES\u5bc4\u5b58\u5668\u4f7f\u7528\u5f97\u6bd4\u8f83\u5c11\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u5e38\u89c1\u7684\u53ea\u6709LEA\u6307\u4ee4\u3002
LEA
\u79f0\u4e3a\u5730\u5740\u4f20\u9001\u6307\u4ee4\uff0c\u683c\u5f0f\u662f\u201cLEA DST, ADDR\u201d\u3002LEA\u5c06ADDR\u5730\u5740\u52a0\u8f7d\u5230DST\uff0c\u5176\u4e2dADDR\u53ef\u4ee5\u662f\u5185\u5b58\uff0c\u4e5f\u53ef\u4ee5\u662f\u5bc4\u5b58\u5668\uff0c\u800cDST\u5fc5\u987b\u662f\u4e00\u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u3002
lea eax, [12345678]; // \u6307\u4ee4\u6267\u884c\u540eeax\u5bc4\u5b58\u5668\u7684\u503c\u4e3a12345678H\nmov eax, [12345678]; // \u800cmov eax, [12345678] \u6307\u4ee4\u6267\u884c\u540eeax\u5bc4\u5b58\u5668\u7684\u503c\u4e3a\u5185\u5b58\u5730\u574012345678\u6307\u5411\u7684\u90a3\u4e2a\u6570\u503c\n// LEA\u6307\u4ee4\u53ef\u7528\u4e8e\u7b97\u6cd5\u8fd0\u7b97\nlea ecx, [ecx + eax*4]; // ecx = ecx + eax * 4\n// \u76f8\u5f53\u4e8e\u8ba1\u7b97\u51faecx+eax*4\u7684\u6570\u503c\uff0c\u5728[]\u91cc\u662f\u4e00\u4e2a\u5730\u5740\uff0clea\u53d6\u5730\u5740\u540e\u5c31\u53d6\u5230\u4e86\u8fd9\u4e2a\u6570\u503c\n
"},{"location":"CS/x86assm/#_15","title":"\u7b97\u6570\u8fd0\u7b97\u6307\u4ee4","text":"80x86\u63d0\u4f9b\u4e868\u6761\u52a0\u51cf\u6cd5\u6307\u4ee4\uff0c4\u6761\u4e58\u9664\u6cd5\u6307\u4ee4\u3002
ADD\uff1a\u52a0\u6cd5\u6307\u4ee4
add eax, esi; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u52a0\u4e0aesi\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u7684\u5bc4\u5b58\u5668\u4e2d\nadd ebx, dword ptr[12345678] // \u5c06ebx\u5bc4\u5b58\u5668\u7684\u503c\u52a0\u4e0a\u5185\u5b58\u5730\u5740\u4e3a12345678\u6240\u5728\u76844\u5b57\u8282\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728ebx\u5bc4\u5b58\u5668\u4e2d\n// \u4e0d\u540c\u7684\u5e73\u53f0\u548c\u7f16\u8bd1\u5668\u4e2d\uff0cdword\u5360\u7528\u7684\u5b57\u8282\u6570\u4e0d\u540c\uff0c\u572832\u4f4d\u7684windows\u4e2d\u4e00\u4e2aword\u536016\u5b57\u8282\uff0cdword\u536032\u5b57\u8282\n// 64\u4f4d\u4e2d\u4e00\u4e2aword\u536032\u5b57\u8282\uff0cdword\u536064\u5b57\u8282\n
sub \u51cf\u6cd5\u6307\u4ee4
sub ecx, 4H; // \u5c06ecx\u5bc4\u5b58\u5668\u7684\u503c\u51cf\u53bb4H\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\nsub byte ptr[eax], ch; // \u5c06\u5185\u5b58\u5730\u5740\u4e3aeax\u6240\u6307\u5411\u7684\u6570\u636e\u7ed3\u6784\u6309\u5b57\u8282\u4e3a\u5355\u4f4d\u548cch\u5bc4\u5b58\u5668\u76f8\u51cf\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u6309\u5b57\u8282\u4e3a\u5355\u4f4d\u4fdd\u5b58\u5728eax\u6240\u6307\u5411\u7684\u4f4d\u7f6e\n
inc\u52a01\u6307\u4ee4
inc eax; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u52a01\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u653e\u5728\u539f\u6765\u7684\u5730\u65b9\n
dec\u51cf1\u6307\u4ee4
dec edx; // \u5c06dec\u5bc4\u5b58\u5668\u7684\u503c\u51cf1\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u653e\u5728\u539f\u6765\u7684\u5730\u65b9\n
cmp\u6bd4\u8f83\u6307\u4ee4
\u79f0\u6bd4\u8f83\u6307\u4ee4\u683c\u5f0f\u662f\u201dcmp oper1, oper2\u201d
cmp\u6307\u4ee4\u5c06oper1\u51cf\u53bboper2\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4e0d\u4fdd\u5b58\uff0c\u53ea\u662f\u76f8\u5e94\u5730\u8bbe\u7f6e\u5bc4\u5b58\u5668eflags\u7684cf\uff0cpf\uff0czf\uff0caf\uff0csf\u548cof\u3002\u4e5f\u5c31\u662f\u8bf4\u53ef\u4ee5\u901a\u8fc7\u6d4b\u8bd5\u5bc4\u5b58\u5668eflags\u76f8\u5173\u7684\u6807\u5fd7\u503c\u5f97\u77e5cmp\u6267\u884c\u540e\u7684\u7ed3\u679c
cmp eax, 56H; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u51cf\u53bb56H\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4e0d\u4fdd\u5b58\uff0c\u5e76\u4e14\u8bbe\u7f6e\u5bc4\u5b58\u5668eflags\u76f8\u5173\u7684\u6807\u5fd7\u4f4d\n
neg
neg\uff1a\u53d6\u8865\u6307\u4ee4\uff0c\u683c\u5f0f\u662fneg oper
neg\u6307\u4ee4\u5c06oper\u64cd\u4f5c\u6570\u53d6\u53cd\uff0c\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\u5c060\u51cf\u53bboper\u64cd\u4f5c\u6570\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u5728oper\u81ea\u8eab\u4e2d\u3002
neg eax; \n
mul imul
\u65e0\u7b26\u53f7\u4e58\u6cd5\u6307\u4ee4\u548c\u6709\u7b26\u53f7\u4e58\u6cd5\u6307\u4ee4\u3002mul\u6307\u4ee4\u9690\u542b\u4e86\u4e00\u4e2a\u53c2\u52a0\u8fd0\u7b97\u7684\u64cd\u4f5c\u6570eax\u5bc4\u5b58\u5668\uff0c\u5c06eax\u5bc4\u5b58\u5668\u91cc\u7684\u503c\u4e58oper\uff0c\u7ed3\u679c\u4fdd\u5b58\u5728eax\u4e2d\u3002\u5982\u679c\u7ed3\u679c\u8d85\u8fc732\u4f4d\u5219\u9ad832\u4f4d\u4f7f\u7528edx\u5bc4\u5b58\u5668\u4fdd\u5b58\uff0ceax\u5bc4\u5b58\u5668\u4fdd\u5b58\u4f4e32\u4f4d\u3002
mul edx; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u4e58\u4ee5edx\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\n
div idiv
\u9664\u6cd5\u6307\u4ee4\u548c\u6709\u7b26\u53f7\u9664\u6cd5\u6307\u4ee4\u3002
div ecx; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u63094\u5b57\u8282\u4e3a\u5355\u4f4d\u9664\u4ee5ecx\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5546\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u4f59\u6570\u4fdd\u5b58\u5728edx\u5bc4\u5b58\u5668\u4e2d\u3002\ndiv word ptr [esp+36]; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u6309word\u4e3a\u5355\u4f4d\u9664\u4ee5\u5806\u6808\u5730\u5740\u4e3aesp+36\u6240\u6307\u5411\u7684\u6570\u636e\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5546\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u4f59\u6570\u4fdd\u5b58\u5728edx\u5bc4\u5b58\u5668\u4e2d\u3002\n
"},{"location":"CS/x86assm/#80386","title":"\u9ad8\u7ea7\u8bed\u8a00\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u4e0e80386\u95f4\u63a5\u5bfb\u5740","text":"BX BP SI DI
BX\uff1a
BP\uff1a
SI\uff1a
DI\uff1a
\u95f4\u63a5\u5bfb\u5740\uff1abx\uff0cbp\uff0csi\uff0cdi\uff0c\u53ef\u4ee5\u653e\u5728\u65b9\u62ec\u53f7\u5185
\u7f3a\u7701\u6bb5\u5740\uff1ads\u548css\uff0c\u5982\u679c\u65b9\u62ec\u53f7\u5185\u6709bp\uff0c\u4e00\u5b9a\u662fss\uff0cbx\u4e00\u5b9a\u662fds
CS (code segment): \u4ee3\u7801\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u4ee3\u7801\u6bb5\u7684\u6bb5\u5730\u5740\u3002
DS (data segment)\uff1a\u6570\u636e\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u6570\u636e\u6bb5\u7684\u6bb5\u5730\u5740\u3002
SS (stack segment)\uff1a\u5806\u6808\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u5806\u6808\u6bb5\u7684\u6bb5\u5730\u5740\u3002
ES (extra segment)\uff1a\u9644\u52a0\u6570\u636e\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u653e\u9644\u52a0\u6bb5\u7684\u6bb5\u5730\u5740\u3002\u6709\u65f6\uff0c\u4e00\u4e2a\u6570\u636e\u6bb5\u4e0d\u591f\u7528\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e\u4e00\u4e2a\u9644\u52a0\u6bb5\u6765\u5b58\u653e\u66f4\u591a\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e 2 \u4e2a\u6570\u636e\u6bb5\uff0c\u5206\u522b\u7528 DS \u548c ES \u6307\u5411\u3002
\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c\u65f6\uff0cDOS \u4f1a\u628a ds \u548c es \u8d4b\u503c\u4e3a psp(program segment prefix) \u6bb5\u5730\u5740\u3002psp \u6bb5\u4f4d\u4e8e\u7a0b\u5e8f\u9996\u4e2a\u6bb5\u7684\u524d\u9762\uff0c\u957f\u5ea6\u4e3a 100h \u5b57\u8282\uff0c\u5176\u7528\u9014\u662f\u4fdd\u5b58\u5f53\u524d exe \u76f8\u5173\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u5982 psp:80h \u5f00\u59cb\u5b58\u653e\u4e86 exe \u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002
\u95f4\u63a5\u5bfb\u5740\uff1a \u53ef\u4ee5\u2f64\u4f5c\u95f4\u63a5\u5bfb\u5740\u7684\u5bc4\u5b58\u5668\u53ea\u6709\u56db\u4e2a\uff1abx, bp, si, di [bx], [bp], [si], [di]\u662f\u6700\u7b80\u5355\u7684\u95f4\u63a5\u5bfb\u5740 [bx + si], [bp + si], [bx + di], [bp + di]\u6ce8\u610f\u524d\u2faf\u5fc5\u987b\u662fbx/bp\uff0c\u540e\u2faf\u5fc5\u987b\u662fdi/si [bx+2] [bp-2] [si+1] [di-1] [bx+si+2] [bx+di-2]
[bp+si+1] [bp+di-1] tips\uff1a\u4e24\u4e2a\u5bc4\u5b58\u5668\u76f8\u52a0\u7684\u95f4\u63a5\u5bfb\u5740\u2f45\u5f0f\u4e2d, bx\u6216bp\u901a\u5e38\u2f64\u6765\u8868\u793a\u6570\u7ec4\u7684\u2fb8\u5730\u5740, \u2f7dsi\u6216di\u5219\u2f64\u6765\u8868\u793a\u4e0b \u6807\u3002
\u7f3a\u7701\u6bb5\u5740\uff1a\u4e0d\u542bbp\u7684\u6e90\u64cd\u4f5c\u6570\u2f00\u822c\u90fd\u7701\u7565\u7684\u6bb5\u5730\u5740ds\uff0c\u542b\u6709bp\u7684\u6e90\u64cd\u4f5c\u6570\u7701\u7565\u4e86ss\uff0c\u2f7d\u8fd9\u4e2a\u9ed8\u8ba4\u7684\u6bb5\u5730\u5740\u662f \u53ef\u4ee5\u88ab\u6539\u53d8\u7684
\u7528\u5806\u6808\u4f20\u9012\u53c2\u6570\u65f6\uff0c\u5982\u4f55\u7528[bp+]\u5b9e\u73b0\u5bf9\u53c2\u6570\u7684\u5f15\u7528\uff1f
bp + \u591a\u5c11\u5c31\u662f\u6808\u91cc\u7684\u591a\u5c11
\u738b\u723d\u300a\u6c47\u7f16\u8bed\u2f94\u300b\u7b2c\u56db\u7248 \u9644\u5f554:\u2f64\u6808\u4f20\u9012\u53c2\u6570
difcube:\n mov bp, sp\n mov ax, [bp+4] ;a\u7684\u503c\u9001\u5165ax\u4e2d\n sub ax, [bp+6] ;\u51cf\u6808\u4e2db\u7684\u503c\n mov bp, ax\n mul bp\n mul bp\n pop bp\n ret 4\n
"},{"location":"CS/x86assm/#_16","title":"\u5176\u5b83\u7684\u7b14\u8bb0","text":""},{"location":"CS/x86assm/#x86_1","title":"x86\uff1a","text":"Intel\u4ece16\u4f4d\u5fae\u5904\u7406\u56688086\u5f00\u59cb\u7684\u6574\u4e2aCPU\u82af\u7247\u7cfb\u5217\uff0c\u7cfb\u5217\u4e2d\u7684\u6bcf\u79cd\u578b\u53f7\u90fd\u4fdd\u6301\u4e0e\u4ee5\u524d\u7684\u5404\u79cd\u578b\u53f7\u517c\u5bb9\uff0c\u4e3b\u8981\u67098086\uff0c8088\uff0816\u4f4dCPU\uff09\uff0c80186\uff0c80286\uff08\u8fd9\u4e24\u4e2a\u662f\u8fc7\u6e21\u4ea7\u54c1\uff09\uff0c 80386\uff0c80486\u4ee5\u53ca\u4ee5\u540e\u5404\u79cd\u578b\u53f7\u7684Pentium\u82af\u7247\uff0832\u4f4dCPU\uff09\uff0c\u901a\u5e38\u6240\u8bf4\u7684x86\u90fd\u662f\u630732\u4f4dCPU
80386: 32\u4f4d\u6c47\u7f16\u3002
80836\u5bc4\u5b58\u5668
\u901a\u7528\u5bc4\u5b58\u5668(EAX EBX ECX EDX,ESP,EBP,ESI,EDI)
\u901a\u7528\u5bc4\u5b58\u5668\u4e0e8086\u7684\u5bc4\u5b58\u5668\u76f8\u6bd4,\u753116\u4f4d\u53d8\u4e3a\u4e8632\u4f4d
ESP:\u6808\u9876
EBP:\u6808\u5e95
EAX\uff0cEBX\uff0cECX\uff0cEDX\u901a\u7528\u5bc4\u5b58\u5668
EAX\uff1a\u7d2f\u52a0\u5668\uff08\u4e58\u6cd5\u7684\u65f6\u5019\u5b58\u4f4e\u4f4d\uff09
EBX\uff1a\u57fa\u5740\uff08\uff3bEBX\uff0b100\uff28\uff3d\uff09
ECX\uff1a\u8ba1\u6570\uff08\u5faa\u73af\u7684\u65f6\u5019\u8ba1\u6570\uff09
EDX\uff1a\u6570\u636e\uff08\u9ed8\u8ba4EDX\uff0a10H\uff0b\uff0e\uff0e\uff0e\uff1b\u4e58\u6cd5\u7684\u65f6\u5019\u5b58\u9ad8\u4f4d\uff09
ESI\uff0cEDI\uff1a\u53d8\u5740\u5bc4\u5b58\u5668
ESI\uff1a\u6e90\u53d8\u5740\u5bc4\u5b58\u5668
EDI\uff1a\u76ee\u7684\u53d8\u5740\u5bc4\u5b58\u5668\u3000\u4e0eEBX\u57fa\u5740\u642d\u914d\u4f7f\u7528
"},{"location":"CS/x86assm/#_17","title":"\u53c2\u8003\u6587\u732e","text":"asm_sum.doc
xxjj\u7684\u300a\u6c47\u7f16\u8bed\u8a00\u8003\u8bd5\u603b\u7ed3\u300b https://www.yuque.com/xianyuxuan/coding/mkte6u
[80386]80x86\u6c47\u7f16\u6307\u4ee4_CarlosX\u7684\u535a\u5ba2-CSDN\u535a\u5ba2_80386\u6307\u4ee4\u96c6
80386 \u7b97\u672f\u8fd0\u7b97\u6307\u4ee4\uff0c\u903b\u8f91\u8fd0\u7b97\u6307\u4ee4\uff0c\u79fb\u4f4d\u6307\u4ee4 (\u4e09) _ttzyanswer\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/CPP/copy/","title":"\u62f7\u8d1d Copy","text":"\u6d45\u62f7\u8d1d\uff08\u9ed8\u8ba4\u62f7\u8d1d\u51fd\u6570\uff09\uff1a\u5c06\u539f\u5bf9\u8c61\u6216\u539f\u6570\u7ec4\u7684\u5f15\u7528\u76f4\u63a5\u8d4b\u503c\u7ed9\u65b0\u5bf9\u8c61\u3001\u65b0\u6570\u7ec4\uff0c\u65b0\u5bf9\u8c61/\u65b0\u6570\u7ec4\u53ea\u662f\u539f\u5bf9\u8c61\u7684\u4e00\u4e2a\u5f15\u7528\u3002 \u6df1\u62f7\u8d1d\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u548c\u6570\u7ec4\uff0c\u5c06\u539f\u5bf9\u8c61\u7684\u5404\u9879\u5c5e\u6027\u7684\u201c\u503c\u201d\uff08\u6570\u7ec4\u91cc\u7684\u6240\u6709\u5143\u7d20\uff09\u62f7\u8d1d\u8fc7\u6765\u3002\u662f\u201c\u503c\u201d\u800c\u4e0d\u662f\u5f15\u7528\u3002
\u4f7f\u7528\u65f6\u6ce8\u610f\uff1a \u6df1\u62f7\u8d1d\u4f1a\u5728\u5806\u5185\u5b58\u91cc\u53e6\u5916\u7533\u8bf7\u7a7a\u95f4\u6765\u50a8\u5b58\u6570\u636e\uff0c\u4ece\u800c\u89e3\u51b3\u4e86\u6307\u9488\u60ac\u6302\u95ee\u9898\u3002\u5f53\u6570\u636e\u6210\u5458\u4e2d\u6709\u6307\u9488\u65f6\uff0c\u5fc5\u987b\u4f7f\u7528\u6df1\u62f7\u8d1d\u3002
\u6df1\u62f7\u8d1d\u7684\u5199\u6cd5
class MyString\n{\nprivate:\nchar *str;\npublic:\nMyString(const char *p=nullstr)//\u7f3a\u7701\u6784\u9020\u51fd\u6570\n:str(nullptr)\n{\nif(p!=nullptr)\n{\nint len=strlen(p)+1;\nstr=new char[len];\nstrcpy_s(str,lrn,p);\n}\n}\nMyString(const MyString& ms)//\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff0c\u6df1\u62f7\u8d1d\n{\nint n = strlen(ms.str) + 1;\n*str = new char[n];\nstrcpy_s = (str, n, ms.str);\n//int *str\n// this->str=new int(*ms.str)\n}\n~MyString()//\u6790\u6784\u51fd\u6570\n{\n}\n}\uff1b\n
"},{"location":"CS/CPP/course/","title":"Courses \u542c\u8bfe","text":""},{"location":"CS/CPP/course/#cs106bcs106l","title":"\u5173\u4e8eCS106B\u548cCS106L","text":"CS106B\u504f\u7b80\u5355\uff0c\u76f8\u5f53\u4e8eZJU\u7684\u6570\u636e\u7ed3\u6784+C++\u7684STL\u7528\u6cd5\u4e00\u5757\u8bb2\uff0c\u53e6\u5916\u518d\u8bb2\u4e00\u4e9bFDS\u7684\u7b97\u6cd5\u3002 CS106L\u662f\u4e13\u95e8\u8bb2C++\u8fdb\u9636\u7279\u6027\u7684\u3002
\u56e0\u4e3a\u5728\u542cCS106B\u4e4b\u524d\u5b66\u8fc7FDS\uff0cCS106B\u82b1\u4e00\u5929\u901f\u901a\u4e86\u4e00\u4e0b\uff0c\u91cd\u590d\u5185\u5bb9\u6709\u70b9\u591a\uff0c\u622a\u4e0b\u4e86\u4e00\u5e45\u56fe\u3002
CS106L\u63d0\u4f9b\u7684C++\u5b66\u4e60\u8def\u7ebf\u56fe
"},{"location":"CS/CPP/course/#zju","title":"ZJU\u8bfe\u7a0b","text":""},{"location":"CS/CPP/course/#_1","title":"\u8bfe\u7a0b\u53c2\u8003\u8d44\u6599","text":"CPP Reference Standard C++ CppCon
"},{"location":"CS/CPP/course/#_2","title":"\u4e0a\u8bfe\u5fc3\u5f97","text":"\u6211\u8ddf\u7684\u662fcx\u8001\u5e08\u7684\u73ed\uff0c\u5e94\u8be5\u662f\u6559\u5f97\u6700\u597d\u7684\u4e00\u6863orz \u4f46\u662f\u4e0a\u8bfe\u5185\u5bb9\u4ecd\u4e0d\u80fd\u8986\u76d6\u4f5c\u4e1a\u548c\u671f\u672b\u7684\u5185\u5bb9\uff0c\u89c9\u5f97\u542c\u8bfe\u5185\u5bb9\u53ea\u80fd\u8d77\u5230\u4e00\u4e2a\u9aa8\u67b6\u4f5c\u7528\uff0c\u8bfe\u540e\u9700\u8981\u82b1\u4e0a\u8bfe2\u81f33\u500d\u7684\u65f6\u95f4\u81ea\u5b66\u81ea\u5df1\u6574\u7406\u7b14\u8bb0\uff0c\u591a\u8bfb\u591a\u5199\u4ee3\u7801\uff0c\u4e0d\u7136\u671f\u672b\u4f1a\u9047\u5230\u6ca1\u89c1\u8fc7\u7684\u7279\u6027\uff0c\u4f1a\u6709\u70b9\u60e8orz\uff08\u50cf\u6211\u4e00\u6837\uff09
"},{"location":"CS/CPP/course/#_3","title":"\u9762\u5411\u5bf9\u8c61\u56db\u5927\u7279\u6027","text":"class Name\n{\n public:\n public_data;\n public_functions;\n protected:\n protected_data;\n protected_functions;\n private:\n private_data;\n private_functions;\n}\n
\u8fd4\u56de\u7c7b\u578b \u7c7b\u540d::\u6210\u5458\u51fd\u6570\u540d\uff08\u53c2\u6570\u8868\uff09 { // \u51fd\u6570\u4f53 }
"},{"location":"CS/CPP/course/#_9","title":"\u5185\u8054\u51fd\u6570\u548c\u5916\u8054\u51fd\u6570","text":"\u53ef\u4ee5\u628a\u76f8\u540c\u6570\u636e\u7ed3\u6784\u548c\u76f8\u540c\u64cd\u4f5c\u96c6\u7684\u5bf9\u8c61\u770b\u4f5c\u5c5e\u4e8e\u540c\u4e00\u7c7b\u3002\u5bf9\u8c61\u662f\u7c7b\u7684\u5b9e\u4f8b\u3002
"},{"location":"CS/CPP/course/#_11","title":"\u5bf9\u8c61\u7684\u5b9a\u4e49","text":"\u5bf9\u8c61\u540d.\u6570\u636e\u6210\u5458\u540d\uff08\u662f \u5bf9\u8c61\u540d.\u7c7b\u540d::\u6210\u5458\u540d \u7684\u7f29\u5199\uff09 \u5bf9\u8c61\u540d.\u6210\u5458\u51fd\u6570\u540d\uff08\u53c2\u6570\u8868\uff09
class Sample\n{\npublic:\nint k;\nint geti(){return i;}\nint getj(){return j;}\nint getk(){return k;}\nprivate:\nint i;\nprotected:\nint j;\n};\nint main()\n{\nSample a;\na.i; // \u975e\u6cd5\na.j: // \u975e\u6cd5\na.k; // \u5408\u6cd5\n}\n
"},{"location":"CS/CPP/course/#_13","title":"\u7c7b\u7684\u4f5c\u7528\u57df","text":"\u7c7b\u7684\u6784\u9020\u51fd\u6570\u662f\u7c7b\u7684\u4e00\u4e2a\u7279\u6b8a\u6210\u5458\u51fd\u6570\uff0c\u6ca1\u6709\u8fd4\u56de\u7c7b\u578b\uff08\u4e0d\u662fvoid\uff09\uff0c\u53ef\u4ee5\u6709\u53c2\u6570\uff0c\u51fd\u6570\u540d\u548c\u7c7b\u540d\u4e00\u6837\u3002\u5f53\u521b\u5efa\u7c7b\u7684\u4e00\u4e2a\u65b0\u5bf9\u8c61\u65f6\uff0c\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570\uff0c\u5b8c\u6210\u521d\u59cb\u5316\u5de5\u4f5c\u3002
"},{"location":"CS/CPP/course/#namespace","title":"Namespace","text":""},{"location":"CS/CPP/course/#namespace_1","title":"\u4ec0\u4e48\u662fnamespace\uff1f","text":"\u662f\u5355\u4e00\u7684\u5168\u5c40\u540d\u5b57\u7a7a\u95f4\u3002\u9632\u6b62\u5728\u4e00\u4e2a\u7a7a\u95f4\u4e2d\u76f8\u540c\u7684\u540d\u5b57\u5f15\u8d77\u51b2\u7a81\u3002 \u4f8b\u5b50\uff1a
namespace myown1\n{\nstring user_name = \"myown1\";\n}\nnamespace myown2\n{\nstring user_name = \"myown2\";\n}\nint main()\n{\n// using namespace myown1; \ncout << \"\\\\n\" << \"Hello, \"\n<< myown1::user_name\n<< \"...and goodbye!\\\\n\"\ncout << \"\\\\n\" << \"Hello, \"\n<< myown2::user_name\n<< \"...and goodbye!\\\\n\"\nreturn 0;\n}\n
\u5173\u952e\u8bcdusing\u5c06\u4e00\u4e2a\u540d\u5b57\u7a7a\u95f4\u53d8\u4e3a\u53ef\u89c1\uff0c\u4e0d\u4f1a\u8986\u76d6\u5f53\u524d\u7684namespace\u3002
"},{"location":"CS/CPP/course/#_15","title":"\u7ee7\u627f\u4e0e\u6d3e\u751f\u7c7b","text":"\u6d3e\u751f\u7c7b\u7ee7\u627f\u4e86\u57fa\u7c7b\u4e2d\u9664\u6784\u9020\u51fd\u6570\u548c\u6790\u6784\u51fd\u6570\u4e4b\u5916\u7684\u6240\u6709\u6210\u5458\u3002\u6d3e\u751f\u7c7b\u7684\u6210\u5458\u5305\u62ec\uff1a - \u7ee7\u627f\u57fa\u7c7b\u7684\u6210\u5458 - \u6d3e\u751f\u7c7b\u5b9a\u4e49\u65f6\u58f0\u660e\u7684\u6210\u5458
\u4ece\u5df2\u6709\u7c7b\u6d3e\u751f\u51fa\u65b0\u7c7b\u65f6\uff0c\u53ef\u4ee5\u5728\u6d3e\u751f\u7c7b\u5185\u5b8c\u6210\u4ee5\u4e0b\u51e0\u79cd\u529f\u80fd\uff1a - \u589e\u52a0\u65b0\u7684\u6570\u636e\u6210\u5458 - \u589e\u52a0\u65b0\u7684\u6210\u5458\u51fd\u6570 - \u91cd\u65b0\u5b9a\u4e49\u57fa\u7c7b\u4e2d\u5df2\u6709\u7684\u6210\u5458\u51fd\u6570 - \u53ef\u4ee5\u6539\u53d8\u73b0\u6709\u6210\u5458\u7684\u5c5e\u6027
\u58f0\u660e\u4e00\u4e2a\u6d3e\u751f\u7c7b\u7684\u4e00\u822c\u683c\u5f0f
class \u6d3e\u751f\u7c7b\u540d:\u7ee7\u627f\u65b9\u5f0f \u57fa\u7c7b\u540d\n{\n// \u6d3e\u751f\u7c7b\u65b0\u589e\u7684\u6570\u636e\u6210\u5458\u548c\u6210\u5458\u51fd\u6570\n};\n
\u4e09\u79cd\u7ee7\u627f\u65b9\u5f0f
class employee: public person\n{};\n// default\nclass employee: private person\n{};\nclass employee: protected person\n{};\n
\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027
\u5728\u57fa\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027 \u7ee7\u627f\u65b9\u5f0f \u5728\u6d3e\u751f\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027 \u89e3\u91ca private public inaccessible \u57fa\u7c7b\u4e2dprivate\u7684\u5bf9\u8c61\u5728\u7c7b\u5916\u5f53\u7136\u4e0d\u53ef\u8bbf\u95ee private private inaccessible private protected inaccessible public public public \u57fa\u7c7b\u4e0d\u7ba1 public private private public protected protected protected public protected \u6743\u9650\u4f1a\u88ab\u7ee7\u627f\u65b9\u5f0f\u7f29\u5c0f\u800c\u4e0d\u4f1a\u653e\u5927 protected private private protected protected protected\u6d3e\u751f\u7c7b\u5bf9\u57fa\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219 - \u5185\u90e8\u8bbf\u95ee\uff1a\u7531\u6d3e\u751f\u7c7b\u4e2d\u65b0\u589e\u6210\u5458\u5bf9\u57fa\u7c7b\u7ee7\u627f\u6765\u7684\u6210\u5458\u7684\u8bbf\u95ee\u3002 - \u5bf9\u8c61\u8bbf\u95ee\uff1a\u5728\u6d3e\u751f\u7c7b\u5916\u90e8\uff0c\u901a\u8fc7\u6d3e\u751f\u7c7b\u7684\u5bf9\u8c61\u5bf9\u4ece\u57fa\u7c7b\u7ee7\u627f\u6765\u7684\u6210\u5458\u7684\u8bbf\u95ee\u3002
\u57fa\u7c7b\u6210\u5458 private\u6210\u5458 public\u6210\u5458 protected\u6210\u5458 \u5185\u90e8\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u53ef\u8bbf\u95ee \u53ef\u8bbf\u95ee \u5bf9\u8c61\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee\u79c1\u6709\u7ee7\u627f\u4e3e\u4f8b
class Point\n{\npublic:\nvoid InitP(float x = 0, float y = 0)\n{\nthis->X = x;\nthis->Y = y;\n}\nvoid Move(float offX, float offY)\n{\nX += offX;\nY += offY;\n}\nfloat GetX() const{return X;}\nfloat GetY() const{return Y;}\nprivate:\nfloat X, Y;\n};\nclass Rectangle: private Point // \u6d3e\u751f\u7c7b\u58f0\u660e\n{\npublic: //\u65b0\u589e\u5916\u90e8\u63a5\u53e3\nvoid InitR(float x, float y, float w, float h)\n{\nInitR(x, y);\nW = w;\nH = h;\n} // \nvoid Move(float xOff, float yOff)\n{\nPoint::\n}\n}\n
"},{"location":"CS/CPP/file_io/","title":"\u6587\u4ef6\u8bfb\u5199 File IO","text":"#include <fstream>\n
ifstream fin;\nofstream fout;\n
\u6587\u4ef6\u6253\u5f00\u65b9\u5f0f
ios::in \u53ea\u8bfb ios::out \u53ea\u5199 ios::app \u4ece\u6587\u4ef6\u672b\u5c3e\u5f00\u59cb\u5199 ios::binary \u4e8c\u8fdb\u5236\u6a21\u5f0f"},{"location":"CS/CPP/final_review/","title":"ZJU \u671f\u672b\u590d\u4e60","text":"\u9762\u5411\u671f\u672b\u9898\u7684\u76f8\u4f3c\u77e5\u8bc6\u70b9\u805a\u7c7b
"},{"location":"CS/CPP/final_review/#_1","title":"\u6784\u9020\u987a\u5e8f","text":"\uff081\uff09main\u51fd\u6570\u4ee5\u5916\u7684\u5bf9\u8c61\uff0c\u5168\u5c40\u7c7b\u5b9a\u4e49\u540e\u76f4\u63a5\u5b9a\u4e49\u7684\u7c7b\u5bf9\u8c61 \uff082\uff09main\u51fd\u6570\u5185\u7684\u5bf9\u8c61 \uff083\uff09\u7236\u7c7b\u6784\u9020 \uff084\uff09\u5b50\u7c7b\u7c7b\u6210\u5458 \uff085\uff09\u5b50\u7c7b\u6784\u9020 \u6790\u6784\u987a\u5e8f\u76f8\u53cd
"},{"location":"CS/CPP/final_review/#_2","title":"\u4ec0\u4e48\u65f6\u5019\u751f\u6210\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff1f","text":"\u5982\u679c\u5df2\u7ecf\u6709\u6784\u9020\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u4e0d\u4f1a\u751f\u6210\u9ed8\u8ba4\u6784\u9020\u51fd\u6570 \u6ca1\u6709\u7684\u65f6\u5019\u4e5f\u4e0d\u4e00\u5b9a\u4f1a\u751f\u6210 \u9700\u8981\u7528\u624d\u751f\u6210
"},{"location":"CS/CPP/final_review/#_3","title":"\u91cd\u8f7d\u89c4\u5219","text":"\u4e0d\u80fd\u91cd\u8f7d\u7684\u6709\uff1a - \u4f5c\u7528\u57df\u64cd\u4f5c\u7b26:: - \u6761\u4ef6\u64cd\u4f5c\u7b26?:\uff08\u5e94\u8be5\u662f\u95ee\u53f7\u8868\u8fbe\u5f0f\uff1f\uff09 - \u70b9\u64cd\u4f5c\u7b26\u3001\u7c7b\u6210\u5458\u6307\u9488 - \u9884\u5904\u7406\u7b26\u53f7#
\u53ea\u80fd\u91cd\u8f7d\u4e3a\u53cb\u5143\u4e0d\u80fd\u6210\u5458\u51fd\u6570\uff1a - <<\u548c>> \u539f\u56e0\u662f\u6210\u5458\u51fd\u6570\u91cd\u8f7d\uff0c\u53ea\u80fd\u5e26\u4e00\u4e2a\u53c2\u6570\uff0clhs\u5fc5\u987b\u662f\u6210\u5458\u81ea\u8eab
\u4f46\u662f\u6d41\u64cd\u4f5c\u7b26\u5de6\u8fb9\u662fcin\u6216cout\uff0c\u91cd\u8f7d\u4e3a\u53cb\u5143\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u6bd4\u6210\u5458\u51fd\u6570\u591a\u8bf4\u660e\u4e00\u4e2a\u5f62\u53c2\u505alhs
\u91cd\u8f7d\u548c\u91cd\u5199\u90fd\u662f\u591a\u6001\uff1a \u91cd\u8f7d\uff1a\u8fd0\u884c\u65f6\u591a\u6001 \u91cd\u5199\uff1a\u7f16\u8bd1\u65f6\u591a\u6001
static\u548cvirtual\u53ea\u80fd\u6709\u4e00\u4e2a
\u6790\u6784\u51fd\u6570\u4e0d\u80fd\u5e26\u53c2\u6570
"},{"location":"CS/CPP/final_review/#_4","title":"\u5b50\u7c7b\u548c\u7236\u7c7b\u6307\u9488","text":"\u4ec0\u4e48\u65f6\u5019\u5fc5\u987b\u7528\u5e38\u5f15\u7528\uff08const &\uff09\uff1a\u5f15\u7528\u578b\u53c2\u6570\u5e94\u5f53\u5728\u80fd\u5b9a\u4e49\u4e3aconst\u7684\u60c5\u51b5\u4e0b\u5c3d\u91cf\u5b9a\u4e49\u4e3aconst\u3002
\u4f7f\u7528\u5f15\u7528\u7684\u4e3b\u8981\u539f\u56e0\uff1a \u7a0b\u5e8f\u80fd\u591f\u4fee\u6539\u8c03\u7528\u51fd\u6570\u4e2d\u7684\u6570\u636e\u5bf9\u8c61 \u901a\u8fc7\u4f20\u9012\u5f15\u7528\u800c\u4e0d\u662f\u6574\u4e2a\u6570\u636e\u5bf9\u8c61\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6
\u53ea\u4f7f\u7528\u4f20\u9012\u8fc7\u6765\u7684\u503c\u800c\u4e0d\u4fee\u6539 \u9700\u8981\u4fee\u6539\u4f20\u9012\u8fc7\u6765\u7684\u503c \u5185\u7f6e\u6570\u636e\u7c7b\u578b\uff08\u5c0f\u578b\u7ed3\u6784\uff09 \u6309\u503c\u4f20\u9012 \u6307\u9488\u4f20\u9012 \u6570\u7ec4 \u6307\u9488\u4f20\u9012 \u6307\u9488\u4f20\u9012 \u8f83\u5927\u7684\u7ed3\u6784\uff09 \u6307\u9488\u6216\u5f15\u7528 \u6307\u9488\u6216\u5f15\u7528 \u7c7b/\u5bf9\u8c61 \u5f15\u7528\u4f20\u9012 \u5f15\u7528\u4f20\u9012\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\uff1a \u53ef\u4ee5\u628a\u5f15\u7528\u7406\u89e3\u6210\u4e00\u4e2a\u5e38\u91cf\u6307\u9488\uff0c\u56e0\u6b64\u5f15\u7528\u58f0\u660e\u65f6\u5c31\u5fc5\u987b\u521d\u59cb\u5316\uff0c\u4e00\u7ecf\u58f0\u660e\u4e0d\u80fd\u518d\u548c\u5176\u5b83\u5bf9\u8c61\u7ed1\u5b9a\u3002
Copy constructor must pass its first argument by reference
"},{"location":"CS/CPP/final_review/#_6","title":"\u7c7b\u5185\u9759\u6001\u6210\u5458\u7684\u521d\u59cb\u5316","text":"const static\u53ef\u4ee5\u5728\u7c7b\u5185\u76f4\u63a5\u521d\u59cb\u5316\uff0c\u975econst static\u6210\u5458\u9700\u8981\u5728\u7c7b\u5916\u521d\u59cb\u5316\u3002
\u53ef\u4ee5\u8c03\u7528\u9ed8\u8ba4\u521d\u59cb\u5316A::n\uff0c\u81ea\u52a8\u521d\u59cb\u5316\u4e3a0\u3002\u6b64\u65f6\u8c03\u7528\u9ed8\u8ba4\u6784\u9020\u4e0d\u80fd\u7528n()\uff0c\u5426\u5219\u8ba4\u4e3a\u662f\u4e2a\u51fd\u6570\u3002\u6216\u8005\u5e26\u521d\u59cb\u503c\u521d\u59cb\u5316A::n(9)
static\u548cconst - \u6ca1\u6709static\u5c31\u662fconst\u7684\u8bf4\u6cd5
const\u7684\u51e0\u79cd\u5f62\u5f0f
const int& fun(int& a); // \u4fee\u9970\u8fd4\u56de\u503c \nint& fun(const int& a); // \u4fee\u9970\u5f62\u53c2 \nint& fun(int& a) const {} // const\u6210\u5458\u51fd\u6570\n
const\u8fd4\u56de\u503c\uff1a\u662f\u4fee\u9970\u8fd4\u56de\u503c\u5f15\u7528\u7c7b\u578b\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u907f\u514d\u8fd4\u56de\u503c\u88ab\u4fee\u6539\u7684\u60c5\u51b5
\u8fd4\u56de\u503c\u662f\u5f15\u7528\u7684\u51fd\u6570\uff0c\u8fd9\u4e2a\u5f15\u7528\u5fc5\u7136\u4e0d\u662f\u4e34\u65f6\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4e00\u5b9a\u662f\u6210\u5458\u53d8\u91cf\u6216\u8005\u51fd\u6570\u53c2\u6570\u3002\uff08\u53ea\u8981\u53c2\u6570\u4e0d\u9700\u8981\u4fee\u6539\u4e00\u5b9a\u52a0\u4e0aconst\uff09
const\u53c2\u6570\u5fc5\u987b\u4f20\u7b7e\u540d\u540e\u5e26const\u7684\u51fd\u6570\uff1a\u8981\u628athis\u6307\u9488\u53d8\u6210const
\u600e\u6837\u6784\u6210\u91cd\u8f7d - \u4e0d\u91cd\u8f7d\u7684
const int& fun(int& a); // \u53c2\u6570\u5217\u8868\u6ca1\u6709\u53d8 \nint& fun(const int a); // \u56e0\u4e3a\u662f\u503c\u4f20\u9012\uff0c\u4e0d\u662fconst\u7684\u4e5f\u80fdtype conversion\n
int& fun(const int& a); // \u56e0\u4e3a\u662f\u53d8\u91cf\u4f20\u9012\uff0c\u8981\u6c42\u68c0\u67e5\u53c2\u6570\u7684const\uff0c\u662f\u53c2\u6570\u5217\u8868\u53d8\u4e86 \nint& fun(int& a) const {} // \u56e0\u4e3a\u9690\u542b\u53c2\u6570this\u7684const\u4e0e\u5426\u4e0d\u4e00\u6837\uff0c\u4e5f\u662f\u53c2\u6570\u5217\u8868\u53d8\u4e86\n
\u200b\u4ee3\u66ff\u5b8f\u7684\u4e00\u79cd\u64cd\u4f5c\uff0c\u5728\u7f16\u8bd1\u9636\u6bb5\u628a\u6240\u6709\u51fd\u6570\u540d\u66ff\u6362\u6210inline function\u7684\u5b9e\u73b0 \u6bd4\u51fd\u6570\u7684\u4f18\u70b9\uff1a\u4e0d\u7528\u9891\u7e41\u8fdb\u6808\u51fa\u6808 \u6bd4\u5b8f\u7684\u4f18\u70b9\uff1a\u6709\u7c7b\u578b\u68c0\u67e5\uff0c\u80fd\u5199\u591a\u884c\uff0c\u80fd\u64cd\u4f5c\u7c7b\u7684\u79c1\u6709\u6210\u5458 inline\u5173\u952e\u5b57\u53ea\u6709\u51fa\u73b0\u5728\u51fd\u6570\u7684\u5b9a\u4e49\u800c\u4e0d\u662f\u58f0\u660e\u524d\u65f6\u624d\u6709\u7528\u3002 \u9759\u6001\u7ed1\u5b9a\u00a0Static\u00a0Binding \u3002\u80fd\u591f\u660e\u786e\u8fd0\u884c\u7684\u662f\u54ea\u4e2a\u7c7b\u7684\u65b9\u6cd5\u65f6\u4f1a\u53d1\u751f\u9759\u6001\u7ed1\u5b9a \u3002\u53d1\u751f\u5728\u7f16\u8bd1\u65f6\u523b\uff0c\u6240\u4ee5\u53c8\u53eb\u65e9\u7ed1\u5b9a \u52a8\u6001\u7ed1\u5b9aDynamic\u00a0Binding \u3002\u51fa\u73b0\u591a\u6001\uff0c\u7f16\u8bd1\u5668\u4e0d\u80fd\u660e\u786e\u5230\u5e95\u4f7f\u7528\u54ea\u4e2a\u7c7b\u7684\u65b9\u6cd5\u65f6\u53d1\u751f\u52a8\u6001\u7ed1\u5b9a \u3002\u53d1\u751f\u5728\u8fd0\u884c\u65f6\u523b\uff0c\u6240\u4ee5\u53c8\u53eb\u665a\u7ed1\u5b9a \u3002\u53ea\u6709\u5b58\u5728\u00a0virtual\u00a0\u65e6\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u65f6\uff0c\u624d\u4f1a\u53d1\u751f\u52a8\u6001\u7ed1\u5b9a
static binding \u7f16\u8bd1\u65f6
class Animal { public: void eat() { cout << \"Animal eats\" << endl; } }; class Dog : public Animal { public: void eat() { cout << \"Dog eats\" << endl; } };\n
dynamic binding \u8fd0\u884c\u65f6
class Animal { public: virtual void eat() { cout << \"Animal eats\" << endl; } }; class Dog : public Animal { public: void eat() { cout << \"Dog eats\" << endl; } };\n
\u200b \u5728\u4e0b\u9762\u7684\u60c5\u51b5\u4e0b\uff0c\u6784\u9020\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff1a - \u5bf9\u4e8e\u5168\u5c40\u5bf9\u8c61\uff0c\u5728main()\u4e24\u6570\u8fd0\u884c\u4e4b\u524d\uff0c\u6216\u8005\u5728\u540c\u4e00\u4e2a\u7f16\u8bd1\u5355\u5143\u5185\u5b9a\u4e49\u7684\u4efb\u4e00\u51fd\u6570\u6216\u5bf9\u8c61 \u88ab\u4f7f\u7528\u4e4b\u524d\u3002\u5728\u540c\u4e00\u4e2a\u7f16\u8bd1\u5355\u5143\u5185\uff0c\u5b83\u4eec\u7684\u6784\u9020\u4e24\u6570\u6309\u7167\u58f0\u660e\u7684\u987a\u5e8f\u521d\u59cb\u5316\u3002 - \u5bf9\u4e8e static\u00a0local\u00a0variables\uff0c\u00a0\u5728\u7b2c\u4e00\u6b21\u8fd0\u884c\u5230\u5b83\u7684\u58f0\u660e\u7684\u65f6\u5019. - \u5bf9\u4e8e automatic\u00a0storage\u00a0duration\u00a0\u7684\u5bf9\u8c61\uff0c\u5728\u5176\u58f0\u660e\u88ab\u8fd0\u884c\u65f6\u3002 - \u5bf9\u4e8e dynamic\u00a0storage\u00a0duration\u00a0\u7684\u5bf9\u8c61\uff0c\u5728\u5176\u7528\u00a0new\u00a0\u8868\u8fbe\u5f0f\u521b\u5efa\u65f6\u3002
"},{"location":"CS/CPP/final_review/#_7","title":"\u667a\u80fd\u6307\u9488","text":"std::unique_ptr<T> //\u72ec\u5360\u8d44\u6e90\u6240\u6709\u6743\u7684\u6307\u9488\u3002 \nstd::shared_ptr<T> //\u5171\u4eab\u8d44\u6e90\u6240\u6709\u6743\u7684\u6307\u9488\u3002 \nstd::weak_ptr<T> //\u5171\u4eab\u8d44\u6e90\u7684\u89c2\u5bdf\u8005\uff0c\u9700\u8981\u548cstd::shared_ptr \u4e00\u8d77\u4f7f\u7528\uff0c\u4e0d\u5f71\u54cd\u8d44\u6e90\u7684\u751f\u547d\u5468\u671f\u3002\n
\u4f7f\u7528\u88f8\u6307\u9488 \u6240\u4ee5\u9ed8\u8ba4\u53c2\u6570\u662f\u548c\u865a\u8868\u65e0\u5173\u4e0e\u5f53\u524d\u7c7b\u578b\u6709\u5173\u5417 \u662f\u7684 \u9ed8\u8ba4\u53c2\u6570\u4e0d\u8fdb\u865a\u8868 \u2192 upcasting\u7684\u65f6\u5019
"},{"location":"CS/CPP/final_review/#upcasting","title":"upcasting","text":"is_a \u903b\u8f91
#include <...>\nclass B{\npublic:\nint f(int i) {cout << \"f(int)\"; return i+1; }\n};\nclass D: public B{\npublic:\nusing B::f; // \u4fdd\u8bc1\u4e0d\u4f1a\u8986\u76d6\u6389B\u4e2d\u7684f\ndouble f(double d) }\n
\u8bbf\u95ee\u63a7\u5236\uff1aprivate\u548cprotected\u7ee7\u627f
int a;\nclass X{\nint a;\n};\nclass XX: public X{\nvoid }\n
\u865a\u7ee7\u627f
\u5411\u4e0a\u8f6c\u578b
Base *pb = &derived;\n
\u8fd9\u4e2a\u4e0d\u4e00\u5b9a\u53ef\u884c
Shape s = c; // object slicing\ns = c; // copy assignment\n
virtual \u5173\u952e\u5b57
\u8bf4\u660e\u4e00\u4e2a non-static member function \u662f\u4e00\u4e2a virtual function
\u884c\u4e3a\u53ef\u4ee5\u88ab\u6d3e\u751f\u7c7boverride\uff08\u91cd\u5199/\u8986\u76d6\uff09
Base::vf\uff0c\u5b50\u7c7b\u6709\u4e00\u4e2a\u540d\u5b57\u3001\u53c2\u6570\u5217\u8868
struct Base {\nvirtual void print() {cout << \"Base\\\\n\"; }\n};\nstruct Derived: public Base{\nvoid }\n
virtual call \u53ea\u5173\u5fc3\u5bf9\u8c61\u7684\u7c7b\u578b\uff0ccall\u5bf9\u5e94\u7c7b\u7684\u51fd\u6570
\u53ea\u8981\u8c03\u7528\u865a\u51fd\u6570\u5c31\u662f\u865a\u8c03\u7528
virtual void do_draw() = 0; // \u662f\u7eaf\u865a\u51fd\u6570\uff0c\u4e0d\u5fc5\u6709\u5b9e\u73b0\uff0c\u4f46\u662f\u53ef\u4ee5\u6709\u5b9e\u73b0\n
\u5982\u679c\u6709\u81f3\u5c11\u4e00\u4e2a\u7eaf\u865a\u51fd\u6570\uff0c\u662f\u62bd\u8c61\u7c7b\uff0c\u62bd\u8c61\u7c7b\u4e0d\u80fd\u7528\u4e8e\u58f0\u660e\u6210\u5458\uff0c\u53ea\u80fd\u4f5c\u4e3a\u57fa\u7c7b
final \u5173\u952e\u5b57\uff1a\u4e0d\u80fd\u88ab\u91cd\u5199\uff0c\u4e0d\u80fd\u88ab\u7ee7\u627f
\u865a\u51fd\u6570\u7684\u901a\u5e38\u5b9e\u73b0\uff1avirtual table (vtable)
static vtable \u865a\u8868
class Der: public Base {\npublic:\nvirtual arbiturary_return_type vir0{}\nvirtual arbiturary_return_type vir1{}\nvirtual arbiturary_return_type vie2{}\n}\n
\u5b83\u7684\u865a\u51fd\u6570\u8868
FunctionPtr Der::__vtable[5]{\n&Der::vir0, &Der::vir1, &Der::vir2, &Base::vir3, &Base::vir4\n}\n
\u597d\u50cf\u5b9e\u9645\u4e0a\u76f8\u5f53\u4e8e\u8fd9\u4e48call\u7684
b.__vptr[3](b);\n
template\u548cOOP\u7684\u533a\u522b\uff0c\u8bed\u4e49\u4e0d\u4e00\u6837\u3002
"},{"location":"CS/CPP/namespace/","title":"\u547d\u540d\u7a7a\u95f4 Namespace","text":"\u547d\u540d\u7a7a\u95f4\uff1a \u540d\u79f0name\u53ef\u4ee5\u662f\u7b26\u53f7\u5e38\u91cf\uff0c\u53d8\u91cf\uff0c\u51fd\u6570\uff0c\u7ed3\u6784\uff0c\u679a\u4e3e\uff0c\u7c7b\u548c\u5bf9\u8c61\u7b49\u3002
\u5b9a\u4e49
namespace A{\nint a = 100;\n}\nnamespace B{\nint b = 200;\n}\nvoid test(){\ncout << A::a << endl;\ncout << B::a << endl;\n}\n
namespace\u53ef\u4ee5\u5d4c\u5957\uff0c\u53ef\u4ee5\u5728namespace\u4e2d\u5b9a\u4e49namespace
namespace A{\nint a = 100;\nnamespace B{\nint a = 2000;\n}\n}\nvoid test(){\ncout << A::a << endl;\ncout << A::B::a << endl;\n}\n
namespace\u662f\u5f00\u653e\u7684\uff0c\u5373\u53ef\u4ee5\u968f\u65f6\u628a\u65b0\u6210\u5458\u52a0\u5165\u5df2\u6709\u7684namespace\u4e2d
namespace A{\nint a = 100;\nint b = 200;\n}\n// \u5c06c\u6dfb\u52a0\u5230\u5df2\u6709\u7684namespace\u4e2d\nnamespace A{\nint c = 300;\n}\nvoid test(){\ncout << A::a << endl;\ncout << A::c << endl;\n}\n
namespace\u53ef\u4ee5\u5b58\u653e\u53d8\u91cf\u548c\u51fd\u6570
namespace A{\nint a = 100;\nvoid func(){\ncout << a << endl;\n}\n}\nvoid test(){\ncout << a << endl;\nA::func();\n}\n
namespace\u4e2d\u7684\u51fd\u6570\u53ef\u4ee5\u5728namespace\u5916\u5b9a\u4e49
namespace A{\nint a = 100;\nvoid func();\n}\n// \u6210\u5458\u51fd\u6570\nvoid A::func(){\ncout << a << endl;\n}\n// \u666e\u901a\u51fd\u6570\nvoid funcb(){\ncout << A::a << endl;\n}\nvoid test(){\nA::func();\nfuncb();\n}\n
\u53d8\u91cf\u540d\u51b2\u7a81\u7684\u89e3\u51b3\u65b9\u6cd5
\u5982\u679c\u5168\u5c40\u53d8\u91cf\u4e0e\u5c40\u90e8\u53d8\u91cf\u51b2\u7a81\uff0c\u90a3\u4e48\u6309\u5c31\u8fd1\u539f\u5219\u6765\u4f7f\u7528\u3002\uff08\uff1f\uff09
"},{"location":"CS/CPP/templates/","title":"\u6a21\u677fTemplate \u548c \u6807\u51c6\u6a21\u677f\u5e93STL","text":"\u9700\u6c42\uff1a\u8ba9\u6211\u4eec\u7684\u4ee3\u7801\u72ec\u7acb\u4e8e\u5177\u4f53\u7684\u7c7b\u578b\u5de5\u4f5c\u3002
\u6211\u4eec\u5199\u51fa\u4e00\u4e2a\u9002\u7528\u4e8e\u6240\u6709\u7c7b\u578b\u7684\u6570\u636e\u7ed3\u6784\u7684\u7c7b\u6216\u7b97\u6cd5\uff08\u51fd\u6570\uff09\uff0c\u5728\u771f\u6b63\u9700\u8981\u4f7f\u7528\u65f6\u751f\u6210\u4e00\u4e2a\u9002\u7528\u4e8e\u6240\u9700\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002\u8fd9\u79cd\u7f16\u7a0b\u8303\u5f0f\u79f0\u4e3a\u8303\u578b\u7f16\u7a0b\u3002
\u6a21\u677f\u7c7b\u7684\u5199\u6cd5
template<typename T>\nclass Container{\nT *data;\nunsigned size, capa;\npiblic:\nContainer(unsigned capa = 512): data(new T[capa]){}\n~Container() {delete[] data;}\nT& operator[](unsigned index) {return data[index];}\n}\n
\u8fd9\u91cctemplate T\u8868\u660e\u5b83\u63a5\u53d7\u4e00\u4e2a\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570\uff0c\u540d\u5b57\u662fT\u3002\u5728\u6a21\u677f\u7684\u5b9a\u4e49\u5185\u90e8\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5230\u8fd9\u4e2a\u7c7b\u578b\u53d8\u91cfT\u3002
\u7279\u5316\uff1a\u6839\u636e\u6a21\u677f\u751f\u6210\u5b9e\u9645\u7684\u7c7b\u7684\u8fc7\u7a0b
Container<int> ci;\nContainer<double> cd;\n
\u6a21\u677f\u51fd\u6570\u8981\u600e\u4e48\u5199
template<typename T>\nT abs(T x) {return x>0?x:-x;}\n
\u6a21\u677f\u8fd0\u7b97\u7b26\u91cd\u8f7d\u600e\u4e48\u5199
template<typename T>\nclass Container {\nT* data;\nunsigned size = 0, capa;\npublic: Container(unsigned capa = 512) : data(new T[capa]), capa(capa){}\n~Container(){delete[] data;}\nT& operator[](unsigned index) {return data[index];}\nconst T& operator[](unsigned idnex) const {return data[index];}\nunsigned getSize() const {return size;}\nunsigned getCapa() const {return capa;}\nContainer &add(T val){\ndata[size++] = val;\nreturn *this;\n}\n};\ntemplate<typename T>\nostream & operator<<(ostream& os, const Container<T>&c){\nfor (unsigned i = 0; i < c.getSize(); i++){\nos << c[i] << ' ';\nreturn os;\n}\n}\n
"},{"location":"CS/CPP/templates/#reference","title":"Reference","text":"7 \u6a21\u677f (I) - \u57fa\u672c\u77e5\u8bc6\u4e0e STL \u4f7f\u7528 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4
"},{"location":"CS/CPP/templates/#template","title":"\u53ef\u53d8\u53c2\u6570\u6a21\u677f templateC++11\u7684\u65b0\u7279\u6027 \u5bf9\u53c2\u6570\u9ad8\u5ea6\u6cdb\u5316\uff0c\u53ef\u4ee5\u8868\u793a0\u5230\u4efb\u610f\u4e2a\u4efb\u610f\u7c7b\u578b\u7684\u53c2\u6570\u3002
\u8bed\u6cd5
template <class ...T> // \u58f0\u660e\u4e00\u4e2a\u53c2\u6570\u5305\uff0c\u8fd9\u4e2a\u53c2\u6570\u5305\u4e2d\u5305\u542b0\u5230\u4efb\u610f\u4e00\u4e2a\u53c2\u6570\u6a21\u677f\nvoid f(T... args); // \u5728\u6a21\u677f\u5b9a\u4e49\u7684\u53f3\u8fb9\uff0c\u53ef\u4ee5\u5c06\u53c2\u6570\u5305\u5c55\u5f00\u6210\u4e00\u4e2a\u4e00\u4e2a\u72ec\u7acb\u53c2\u6570\n
\u6700\u5927\u7684\u96be\u70b9\uff1a\u5982\u4f55\u5c55\u5f00\u53ef\u53d8\u6a21\u677f\u53c2\u6570
\u6253\u5370\u53c2\u6570\u4e2a\u6570\uff1a
template<class ...T>\nvoid f(T... args)\n{\n cout << sizeof...(args) << endl;\n}\n\nf();\nf(1, 2);\nf(1, 2.5, \"\");\n
\u9012\u5f52\u65b9\u5f0f\u5c55\u5f00\u53c2\u6570\u5305
#include <iostream>\nusing namespace std;\n\n// \u9012\u5f52\u7ec8\u6b62\u51fd\u6570\nvoid print(){\n cout << \"empty\" << endl;\n}\n\n// \u5c55\u5f00\u51fd\u6570\ntemplate<class T, class ...Args>\nvoid print(T head, Args... rest){\n cout << \"parameter\" << head << endl;\n print(rest...);\n}\n\nint main(){\n print(1, 2, 3, 4);\n return 0;\n}\n
\u4e0a\u8ff0\u4f8b\u5b50\u4f1a\u8f93\u51fa\u6bcf\u4e00\u4e2a\u53c2\u6570\uff0c\u76f4\u5230\u7a7a\u65f6\u8f93\u51faempty\u3002\u5c55\u5f00\u53c2\u6570\u5305\u7684\u51fd\u6570\u6709\u4e24\u4e2a\uff0c\u4e00\u4e2a\u662f\u9012\u5f52\u51fd\u6570\uff0c\u53e6\u4e00\u4e2a\u662f\u9012\u5f52\u7ec8\u6b62\u51fd\u6570\uff0c\u53c2\u6570\u5305Args\u2026\u5728\u5c55\u5f00\u7684\u8fc7\u7a0b\u4e2d\u9012\u5f52\u8c03\u7528\u81ea\u5df1\uff0c\u6bcf\u8c03\u7528\u4e00\u6b21\uff0c\u53c2\u6570\u5305\u4e2d\u7684\u53c2\u6570\u5c31\u5c11\u4e00\u4e2a\uff0c\u76f4\u5230\u6240\u6709\u53c2\u6570\u90fd\u5c55\u5f00\u4e3a\u6b62\u3002\u5f53\u6ca1\u6709\u53c2\u6570\u65f6\uff0c\u5219\u8c03\u7528\u975e\u6a21\u677f\u51fd\u6570print()\u7ec8\u6b62\u9012\u5f52\u8fc7\u7a0b\u3002
\u7ec8\u6b62\u51fd\u6570\u4e5f\u53ef\u4ee5\u5199\u6210
template<class T>\nvoid print(T t){\n cout << t << endl;\n}\n
\u53ef\u53d8\u6a21\u677f\u53c2\u6570\u6c42\u548c
template<typename T>\nT sum(T t){\n return t;\n}\ntemplate<typename T, typename ... Types>\nT sum(T first, Types ...rest){\n return first + sum<T> (rest...);\n}\n\nsum(1, 2, 3, 4);\n
\u9012\u5f52\u51fd\u6570\u5c55\u5f00\u53c2\u6570\u5305\u662f\u4e00\u79cd\u6807\u51c6\u505a\u6cd5\uff0c\u4e5f\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u4f46\u662f\u7f3a\u70b9\u65f6\u5fc5\u987b\u8981\u4e00\u4e2a\u91cd\u8f7d\u7684\uff08\u540c\u540d\uff09\u9012\u5f52\u7ec8\u6b62\u51fd\u6570\u6765\u7ec8\u6b62\u9012\u5f52\u3002
\u6216\u8005\u4e0d\u9012\u5f52\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u501f\u52a9\u9017\u53f7\u8868\u8fbe\u5f0f\u548c\u521d\u59cb\u5316\u5217\u8868\u3002\u524d\u9762\u7684print\u53ef\u4ee5\u8fd9\u4e48\u5199
template<class T>\nvoid printarg(T t){\n cout << t << endl;\n}\n\ntemplate <class ...Args>\nvoid expand(Args... args){\n int arr[] = {(printarg(args), 0)...};\n}\n\nexpand(1, 2, 3, 4);\n
arr\u8fd9\u4e2a\u6570\u7ec4\u7684\u76ee\u7684\u5355\u7eaf\u662f\u5c55\u5f00\u53c2\u6570\u5305
\u5982\u679c\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u652f\u6301lambda\u8868\u8fbe\u5f0f
template<class F, class... Args> void expand(const F& f, Args&&...args){\ninitializer_list<int>{(f(std::forward< Args>(args)), 0)};\n}\nexpand([](int i){cout << i << endl;}, 1,2,3);\n
\u53ef\u4ee5\u5e26\u4efb\u610f\u4e2a\u6570\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u6bd4\u5982std::tuple
template<class... Types>\nclass tuple;\n
\u6a21\u677f\u504f\u7279\u5316\u548c\u9012\u5f52\u65b9\u5f0f\u5c55\u5f00\u53c2\u6570\u5305
\u53ef\u53d8\u53c2\u6570\u6a21\u677f\u7c7b\u7684\u5c55\u5f00\u4e00\u822c\u9700\u8981\u5b9a\u4e49\u4e24\u5230\u4e09\u4e2a\u7c7b\uff0c\u5305\u62ec\u7c7b\u58f0\u660e\u548c\u504f\u7279\u5316\u7684\u6a21\u677f\u7c7b
// \u524d\u5411\u58f0\u660e\ntemplate<typename... Args>\nstruct Sum;\n\n// \u57fa\u672c\u5b9a\u4e49\ntemplate<typename First, typename... Rest>\nstruct Sum<First, Rest...>{\n enum { value = Sum<First>::value + Sum<Rest...>::value };\n}\n\n// \u9012\u5f52\u7ec8\u6b62\ntemplate<typename Last>\nstruct Sum<Last>{\n enum { value = sizeof(Last) };\n}\n
","text":""},{"location":"CS/CPP/templates/#stl","title":"\u6807\u51c6\u6a21\u677f\u5e93 STL STL\u516d\u5927\u90e8\u4ef6\uff1a\u5bb9\u5668\uff08containers\uff09\uff0c\u5206\u914d\u5668\uff08allocators\uff09\uff0c\u7b97\u6cd5\uff08algorithm\uff09\uff0c\u8fed\u4ee3\u5668\uff08iterator\uff09\uff0c\u9002\u914d\u5668\uff08adapters\uff09\uff0c\u4eff\u51fd\u6570\uff08functors\uff09
","text":""},{"location":"CS/CPP/templates/#_1","title":"\u5e38\u7528\u7684\u5bb9\u5668","text":"vector, deque, list, set/multiset, map/multimap \u7b49
"},{"location":"CS/CPP/templates/#1-vector","title":"1. Vector","text":"Vector\u662f\u4e00\u79cd\u53d8\u957f\u6570\u7ec4\u3002
#include<vector>\nusing namespace std;\nvector<int> name;\nvector<double> name;\nvector<char> name;\nvector<struct node> name;\n// \u8fd9\u4e24\u4e2a\u4e3b\u8981\u6709\u901f\u5ea6\u4e0a\u7684\u533a\u522b\uff0carray\u975e\u5e38\u6162\uff0cvector\u5feb\u4e00\u4e9b\nvector< vector<int> > name; // > >\u4e4b\u95f4\u8981\u52a0\u7a7a\u683c\uff0c\u65b0\u6807\u51c6\u4e0d\u7528\u52a0\u4e86\nvector<int> array[SIZE]; // \u8fd9\u4e2a\u4e0d\u662f\u5f88\u5e38\u7528\uff0c\u56e0\u4e3a\u5bb9\u6613\u51fa\u9519\uff0c\u4e14\u6570\u7ec4\u4e0d\u77e5\u9053\u81ea\u5df1\u7684\u957f\u5ea6\uff0c\u8fd8\u6709std::array\n
\u8bbf\u95ee\u65b9\u5f0f
// 1. \u901a\u8fc7\u4e0b\u6807\n#include<iostream>\n#include<vector>\nusing namespace std;\nint main()\n{\nvector<int> vi;\nvi.push_back(1);\ncout<<vi[0]<<endl;\nreturn 0;\n}\n// 2. \u901a\u8fc7\u8fed\u4ee3\u5668\nvector<int>::iterator\nvector<double>::iterator\n// \u4f8b\n#include<iostream>\n#include<vector>\nint main()\n{\nvector<int> v;\nfor(int i = 0; i < 5; i++)\n{\nv.push_back(i); }\nvector<int>::iterator it=v.begin();\nfor(int i = 0; i < v.size(); i++)\n{\ncout << it[i] << \" \";\n// \u4e5f\u53ef\u4ee5\u5199\u6210 cout << * (it + i) << \" \";\n}\nreturn 0;\n}\n// \u6216\u8005\u4f18\u96c5\u7684\u5199\u6cd5\n// \u56e0\u4e3a\u8fed\u4ee3\u5668\u4e0d\u652f\u6301 it < v.end()\u7684\u5199\u6cd5\uff0c\u53ea\u80fd\u5199!=\nfor (vector<int>::iterator it=v.begin(); it!=v.end();it++)\n{\ncout << *it << \" \";\n}\n
\u5e38\u7528\u51fd\u6570 push_back(item) // \u5728vector\u540e\u9762\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\npop_back(item) // \u5728vector\u540e\u9762\u5220\u9664\u4e00\u4e2a\u5143\u7d20\nsize(vector) // \u8fd4\u56de\u5143\u7d20\u4e2a\u6570\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(1)\nclear(vector) // \u6e05\u9664\u6240\u6709\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(N)\ninsert(position, x) // \u5728position\u7684\u5730\u65b9\u63d2\u5165\u4e00\u4e2ax\n// \u4f8b\nv.insert(v.begin()+2, -1); // \u76f8\u5f53\u4e8e\u5728v[2]\u5904\u63d2\u5165\u4e00\u4e2a-1\nerase(position);\nerase(positionBegin, positionEnd); // \u5de6\u95ed\u53f3\u5f00\n
"},{"location":"CS/CPP/templates/#2-set","title":"2. set","text":"\u96c6\u5408\u662f\u4e0d\u5141\u8bb8\u5143\u7d20\u91cd\u590d\u7684\u65e0\u5e8f\u5bb9\u5668
#include<set>\nusing namespace std;\nset<int> name;\nset<double> name;\nset<char> name;\nset<struct node> name;\nset<set<int> > name;\n
\u56e0\u4e3a\u65e0\u5e8f\uff0cset\u53ea\u80fd\u901a\u8fc7iterator\u8bbf\u95ee\uff0c\u9664\u4e86vector\u548cstring\u4e4b\u5916\u7684\u5bb9\u5668\u90fd\u4e0d\u80fd\u901a\u8fc7\u4e0b\u6807\u8bbf\u95ee set<int>::iterator it;\nset<char>::iterator it;\n
\u5e38\u7528\u51fd\u6570 st.insert(X);\nst.find(X); // \u8fd4\u56deset\u4e2dvalue\u6240\u5bf9\u5e94\u7684\u8fed\u4ee3\u5668\uff0c\u4e5f\u5c31\u662fvalue\u7684\u6307\u9488\n// \u4f8b\nset<int>::iterator it = st.find(2);\ncout << *it << endl;\n// \u53ef\u4ee5\u76f4\u63a5\u5199\u6210\ncout << *(st.find(2)) << endl;\nst.erase(it); // \u5220\u9664\u67d0\u4e2a\u5730\u5740\u7684\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(1)\nst.erase(X); // \u5220\u9664\u67d0\u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(N)\nst.erase(itBegin, itEnd);\nst.size();\n
"},{"location":"CS/CPP/templates/#3-deque","title":"3. deque","text":"deque\u662f\u7531\u4e00\u6bb5\u5b9a\u91cf\u8fde\u7eed\u7a7a\u95f4\u6784\u6210\uff0c\u4e00\u65e6\u8981\u5728deque\u7684\u524d\u7aef\u548c\u5c3e\u7aef\u589e\u52a0\u7a7a\u95f4\uff0c\u4fbf\u914d\u7f6e\u4e00\u6bb5\u8fde\u7eed\u7a7a\u95f4\uff0c\u4e32\u5728\u6574\u4e2adeque\u7684\u5934\u90e8\u548c\u5c3e\u90e8.
"},{"location":"CS/CPP/templates/#4-list","title":"4. list","text":""},{"location":"CS/CPP/templates/#5-mapunordered_map","title":"5. map/unordered_map","text":""},{"location":"CS/CPP/templates/#6-string","title":"6. string","text":"// init\n#include<string>\nstring str;\nstring str = \"Hello\";\ncin >> str;\ncout << str;\n// assignment\nchar cstr1[20];\nchar cstr2[20] = \"jaguar\";\nstring str1;\nstring str2 = \"panther\";\ncstr1 = cstr2; // illegal\nstr1 = str2; // legal\n// concatenation\nstring str3;\nstr3 = str1 + str2;\nstr1 += str2;\nstr1 += \"a string literal\";\n// constructors (Ctors)\nstring (const char *cp, int len);\nstring (const string& s2, int pos);\nstring (const string& s2, int pos, int len);\n// sub-string\nsubstr (int pos, int len);\n// modification\nassign (...);\ninsert (...);\ninsert (int pos, const string& s);\nerase (...);\nappend (...);\nreplace (...);\nreplace (int pos, int len, const string& s);\n...\n// search\nfind (const string& s);\n// File I/O\n#include <ifstream> // read from file\n#include <ofstream> // write to file\n// write into file\nofstream File1(\"...\");\nFile1 << \"Hello world\" << std::enl;\n// read from file\nifstream File2(\"...\");\nstd::string str;\nFile2 >> str;\n
"},{"location":"CS/CPP/templates/#_2","title":"\u7b97\u6cd5","text":"\u7b97\u6cd5\u90e8\u5206\u4e3b\u8981\u7531<algorithm> <numeric> <functional>
\u7ec4\u6210 <algorithm>
\u662f\u6700\u5927\u7684\u4e00\u4e2a <numeric>
\u4f53\u79ef\u5f88\u5c0f\uff0c\u53ea\u5305\u62ec\u51e0\u4e2a\u5728\u5e8f\u5217\u4e0a\u8fdb\u884c\u7b80\u5355\u6570\u5b66\u8fd0\u7b97\u7684\u6a21\u677f\u51fd\u6570 <functional>
\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6a21\u677f\u7c7b\uff0c\u7528\u4ee5\u58f0\u660e\u51fd\u6570\u5bf9\u8c61
\u7528\u8fed\u4ee3\u5668\u53ef\u4ee5\u8bfb\u53d6\u5b83\u6307\u5411\u7684\u5143\u7d20\u3002\u8fed\u4ee3\u5668\u540d\u5c31\u8868\u793a\u8fed\u4ee3\u5668\u6307\u5411\u7684\u5143\u7d20\uff0c\u901a\u8fc7\u975e\u5e38\u91cf\u8fed\u4ee3\u5668\u8fd8\u80fd\u4fee\u6539\u5176\u6307\u5411\u7684\u5143\u7d20\u3002
#include<iostream> #include<vector> using namespace std; int main() { vector<int> v; for (int n = 0; n < 5; ++n) v.push_back(n); vector<int>::iterator i; for (i = v.begin(); i != v.end(); i++) { cout << *i << \" \"; // *i \u662f i \u6307\u5411\u7684\u5143\u7d20 *i *= 2; \n} }\n
"},{"location":"CS/CPP/templates/#stl_1","title":"\u7c7b\u5e93\u548cSTL STL\u662f\u8303\u578b\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u4e00\u4e2a\u8303\u4f8b\uff0c\u542b\uff1a\u5bb9\u5668\uff08container\uff09\u3001\u8fed\u4ee3\u5668\uff08iterator\uff09\u3001\u7b97\u6cd5\uff08algorithm\uff09\u3001\u51fd\u6570\u5bf9\u8c61\uff08function object\uff09\u3002\u7c7b\u5e93\u662f\u7c7b\u7684\u96c6\u5408\uff0c\u662f\u4e00\u79cd\u9884\u5b9a\u4e49\u7684\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u5e93\u3002
","text":""},{"location":"CS/CPP/templates/#c","title":"C++\u7684\u6807\u51c6\u5e93","text":"using namespace std;
\u5bb9\u5668\uff08container\uff09\u7c7b\u662f\u7528\u6765\u5bb9\u7eb3\u3001\u5305\u542b\u4e00\u7ec4\u5143\u7d20\u6216\u5143\u7d20\u96c6\u5408\u7684\u5bf9\u8c61\u7684\u3002STL\u4e2d\u5b9a\u4e49\u4e86\u591a\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u5bb9\u5668\uff0c\u4f8b\u5982
\u5b9a\u4e49
vector<int> iv;\nvector<int> cv(5);\nvector<int> cv(5, 'x');\nvector<int> iv2(iv);\n
\u4f7f\u7528
#include<iostream>\n#include<vector>\nusing namespace std;\nint main()\n{\nvector<char> v; // create zero-len vector\nint i;\n// put values into a vector\nfor (i = 0; i < 10; i++)\nv.push_back('A' + i);\n// can access vector contents using subsripting\nfor (i = 0; i < 10; i++)\ncout << v[i] << \" \";\ncout << endl;\n// access via iterator\nvector<char>::iterator p = v.begin();\nwhile(p != v.end())\n{\ncout << *p << \" \";\np++;\n}\nreturn 0;\n}\n
"},{"location":"CS/CPP/templates/#list","title":"\u7ebf\u6027\u8868 list","text":"\u5b9a\u4e49\u4e86\u53cc\u5411\u7684\u7ebf\u6027\u8868\uff0c\u53c8\u53ef\u79f0\u4e3a\u53cc\u5411\u94fe\u8868\u3002list\u7c7b\u53ea\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002
// sort a list\n#include<iostream>\n#include<list>\n#include<cstdlib>\nusing namespace std;\nint main()\n{\nint i;\nlist<char> lst;\n// create a list of random characters\nfor (i = 0; i < 10; i++)\nlist.push_back('A' + (rand()%26));\n}\n
"},{"location":"CS/CPP/templates/#set","title":"\u96c6\u5408 set","text":"#include<set>\n#include<iostream>\n#include<string>\nint main()\n{\nstd::set<std::string> source;\nstd::string input;\nfor(int i=0;i<6;i++)\n{\nstd::cin>>input;\nsource.insert(input);\n}\nstd::set<std::string>::iterator at = source.begin();\nwhile(at != source.end())\nstd::cour << * at++ << std::endl;\n}\n
"},{"location":"CS/CPP/templates/#multiset","title":"multiset","text":""},{"location":"CS/CPP/templates/#map","title":"\u6620\u5c04 map","text":""},{"location":"CS/CPP/templates/#queue","title":"\u961f\u5217 queue","text":""},{"location":"CS/CPP/templates/#stdstack","title":"std::stack","text":""},{"location":"CS/CPP/templates/#stdpair","title":"std::pair","text":""},{"location":"CS/CPP/templates/#string","title":"\u5b57\u7b26\u4e32string","text":""},{"location":"CS/CPP/templates/#_3","title":"\u7b97\u6cd5\u5e93 ` #include<algorithm>\n#include<iostream>\n#include<string>\n#include<vector>\nusing namespace std;\nvoid load(vector<string>&);\nvoid print(vector<string>);\nconst int SIZE = 8;\nint main()\n{\nvector<string> v(SIZE);\nload(v);\nsort(v.begin(), v.end()); // \u6307\u5b9a\u6392\u5e8f\u7684\u8d77\u6b62\u4f4d\u7f6e\nprint(v);\nreturn 0;\n}\n// \u4f1a\u6309\u7167\u5b57\u6bcd\u5e8f\u6392\u5e8f\n
"},{"location":"CS/CPP/templates/#_4","title":"\u8fed\u4ee3\u5668 \u662f\u4e00\u79cd\u7c7b\u4f3c\u6307\u9488\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u5668\u6765\u8bbf\u95ee\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u3002
#include<list>\n#include<iostream>\nint main()\n{\nusing namespace std;\nlist<int> c1;\nlist<int>::iterator c1_Iter;\nlist<int>::reverse_iterator c1_rIter;\nc1_rIter = c1.rbegin(); // the last element\n}\n
"},{"location":"CS/CPP/templates/#_5","title":"\u53c2\u8003\u8d44\u6599 https://zhuanlan.zhihu.com/p/344558356 LJJ PPT
","text":""},{"location":"CS/CPP/type/","title":"\u7c7b\u578b\u548c\u7c7b\u578b\u8f6c\u6362 Type & Type Conversion","text":""},{"location":"CS/CPP/type/#type-info","title":"Type info \u5e93","text":"#include <typeinfo>\n
\u7b80\u4ecb - \u548csizeof\u8fd9\u7c7b\u64cd\u4f5c\u7b26\u4e00\u6837\uff0ctypeid\u662fc++\u7684\u5173\u952e\u5b57\u4e4b\u4e00 - typeid\u64cd\u4f5c\u7b26\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u540d\u4e3atype_info\u7684\u6807\u51c6\u5e93\u7c7b\u578b\u7684\u5bf9\u8c61\u7684\u5f15\u7528\uff08\u5728\u5934\u6587\u4ef6typeinfo\u4e2d\u5b9a\u4e49\uff09 - c++\u5e76\u6ca1\u6709\u89c4\u5b9atypeid\u5b9e\u73b0\u6807\u51c6\uff0c\u5404\u4e2a\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u4e0d\u4e00\u6837 - \u7f16\u8bd1\u5668\u4f1a\u4e3a\u6bcf\u4e00\u79cdtypeid\u64cd\u4f5c\u7684\u7c7b\u578b\u751f\u6210\u4e00\u4efd\u4fdd\u5b58\u5728\u6570\u636e\u6bb5\u7684type_info\u6570\u636e - \u6bcf\u79cd\u7c7b\u578b\u7684type_info\u6570\u636e\u957f\u5ea6\u4f9d\u8d56\u4e8e\u7c7b\u578b\u540d\u79f0\uff0c\u81f3\u5c119\u4e2a\u5b57\u8282
\u7528\u6cd5 - \\== \u548c!=\u64cd\u4f5c
#include <iostream>\n#include <typeinfo>\nstruct Base{};\nstruct Derived: Base {};\nstruct Poly_Base {virtual void Member(){}};\nstruct Poly_Derived: Poly_Base {};\ntypedef int my_int_type;\nint main()\n{\nstd::cout << std::boolalpha;\nstd::cout << \"int vs my_int_type: \";\nstd::cout << (typeid(int) == typeid(my_int_type)) << '\\\\n';\nstd::cout << \"Base vs Derived: \";\nstd::cout << (typeid(Base) == typeid(Derived)) << '\\\\n'; // \u8f93\u51fafalse\nBase* pbase = new Derived;\n}\n
#include <iostream>\n#include <typeinfo>\nstruct Base{}\nstruct Derived: Base{};\ntemplate <class T>\nvoid swap(T a, T b){\nstd::cout << \"T is: \" << typeid(T).name() << '\\\\n';\nT temp = a;\na = b;\nb = temp;\n}\nint main(){\nint i;\nint* ptr;\nstd::cout << \"int is: \" << typeid(int).name() << '\\\\n';\nstd::cout << \" i is: \" << typeid(i).name() << '\\\\n';\n}\n
\u53c2\u8003 C++\u4e2d\u7684typeInfo\u7528\u6cd5\u603b\u7ed3_\u975e\u665a\u975e\u665a\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/CPP/type/#_1","title":"\u7c7b\u578b\u8f6c\u6362","text":""},{"location":"CS/CPP/type/#const_cast","title":"const_cast","text":"const_cast<new_type>(expression);\n
#include <iostream>\nstruct type\n{\nint i;\ntype(): i(3) {}\nvoid f(int v) const\n{\n// this->i = v; // compile error: this is a pointer to const\nconst_cast<type*>(this)->i = v; // OK as long as the type object isn't const\n}\n};\nint main()\n{\nint i = 3; // i is not declared const\nconst int& rci = i;\nconst_cast<int&>(rci) = 4; // OK: modifies i\nstd::cout << \"i = \" << i << '\\\\n';\ntype t; // if this was const type t, then t.f(4) would be undefined behavior\nt.f(4);\nstd::cout << \"type::i = \" << t.i << '\\\\n';\nconst int j = 3; // j is declared const\n[[maybe_unused]]\nint* pj = const_cast<int*>(&j);\n// *pj = 4; // undefined behavior\n[[maybe_unused]]\nvoid (type::* pmf)(int) const = &type::f; // pointer to member function\n// const_cast<void(type::*)(int)>(pmf); // compile error: const_cast does\n// not work on function pointers\n}\n
"},{"location":"CS/CPP/type/#dynamic_cast","title":"dynamic_cast","text":"dynamic_cast<new_type>(expression);\n
#include <iostream>\nstruct V\n{\nvirtual void f() {} // must be polymorphic to use runtime-checked dynamic_cast\n};\nstruct A : virtual V {};\nstruct B : virtual V\n{\nB(V* v, A* a)\n{\n// casts during construction (see the call in the constructor of D below)\ndynamic_cast<B*>(v); // well-defined: v of type V*, V base of B, results in B*\ndynamic_cast<B*>(a); // undefined behavior: a has type A*, A not a base of B\n}\n};\nstruct D : A, B\n{\nD() : B(static_cast<A*>(this), this) {}\n};\nstruct Base\n{\nvirtual ~Base() {}\n};\nstruct Derived: Base\n{\nvirtual void name() {}\n};\nint main()\n{\nD d; // the most derived object\nA& a = d; // upcast, dynamic_cast may be used, but unnecessary\n[[maybe_unused]]\nD& new_d = dynamic_cast<D&>(a); // downcast\n[[maybe_unused]]\nB& new_b = dynamic_cast<B&>(a); // sidecast\nBase* b1 = new Base;\nif (Derived* d = dynamic_cast<Derived*>(b1); d != nullptr)\n{\nstd::cout << \"downcast from b1 to d successful\\\\n\";\nd->name(); // safe to call\n}\nBase* b2 = new Derived;\nif (Derived* d = dynamic_cast<Derived*>(b2); d != nullptr)\n{\nstd::cout << \"downcast from b2 to d successful\\\\n\";\nd->name(); // safe to call\n}\ndelete b1;\ndelete b2;\n}\n
"},{"location":"CS/CPP/type/#reinterpret_cast","title":"reinterpret_cast","text":"reinterpret_cast<new_type>(expression)\n
#include <cassert>\n#include <cstdint>\n#include <iostream>\nint f() { return 42; }\nint main()\n{\nint i = 7;\n// pointer to integer and back\nstd::uintptr_t v1 = reinterpret_cast<std::uintptr_t>(&i); // static_cast is an error\nstd::cout << \"The value of &i is \" << std::showbase << std::hex << v1 << '\\\\n';\nint* p1 = reinterpret_cast<int*>(v1);\nassert(p1 == &i);\n// pointer to function to another and back\nvoid(*fp1)() = reinterpret_cast<void(*)()>(f);\n// fp1(); undefined behavior\nint(*fp2)() = reinterpret_cast<int(*)()>(fp1);\nstd::cout << std::dec << fp2() << '\\\\n'; // safe\n// type aliasing through pointer\nchar* p2 = reinterpret_cast<char*>(&i);\nstd::cout << (p2[0] == '\\\\x7' ? \"This system is little-endian\\\\n\"\n: \"This system is big-endian\\\\n\");\n// type aliasing through reference\nreinterpret_cast<unsigned int&>(i) = 42;\nstd::cout << i << '\\\\n';\n[[maybe_unused]] const int &const_iref = i;\n// int &iref = reinterpret_cast<int&>(\n// const_iref); // compiler error - can't get rid of const\n// Must use const_cast instead: int &iref = const_cast<int&>(const_iref);\n}\n
"},{"location":"CS/CPP/type/#static_cast","title":"static_cast","text":"static_cast<new_type>(expression)\n
struct B {}; struct D : B { B b; }; D d; B& br1 = d; B& br2 = d.b; static_cast<D&>(br1); // OK: lvalue denoting the original d object \nstatic_cast<D&>(br2); // UB: the b subobject is not a base class subobject\n
ZJU OS\u64cd\u4f5c\u7cfb\u7edf\u8bfe\u7a0b\u7b14\u8bb0\u3002
\u4f9b\u81ea\u5b66\u800c\u5199\u7684\uff0c\u4e0d\u4fdd\u8bc1\u5199\u5f97\u6613\u61c2\u3002\u56e0\u6b64\u4e0d\u5efa\u8bae\u9605\u8bfb\uff01
\u63a8\u8350\u53c2\u8003\u8d44\u6599
\u3010\u7b14\u8bb0\u3011RISC-V ISA - \u9e64\u7fd4\u4e07\u91cc\u7684\u7b14\u8bb0\u672c (tonycrane.cc)
\u3010\u7b14\u8bb0\u3011Unit 4: \u5b58\u50a8\u7ba1\u7406 | Storage Management [\u672a\u5b8c\u6210] - Isshiki\u4fee's Notebook (isshikih.top)
\u3010\u7b14\u8bb0\u30111 \u5199\u5728\u524d\u9762 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io)
\u3010\u4e60\u9898\u3011rCore-Tutorial-Book-v3 3.6.0-alpha.1 \u6587\u6863 (rcore-os.cn)
\u3010\u6587\u6863\u3011RISC-V\u624b\u518c (riscvbook.com)
\u3010\u6587\u6863\u3011makefile\u4ecb\u7ecd \u2014 \u8ddf\u6211\u4e00\u8d77\u5199Makefile 1.0 \u6587\u6863 (seisman.github.io)
\u3010\u6587\u6863\u3011riscv-asm-manual/riscv-asm.md at master \u00b7 riscv-non-isa/riscv-asm-manual (github.com)
"},{"location":"CS/OS/mem_file/","title":"OS Lecture \u5185\u5b58\u548c\u6587\u4ef6\u7cfb\u7edf","text":""},{"location":"CS/OS/mem_file/#8","title":"8. \u4e3b\u5b58","text":"\u5e38\u8bc6\uff1a
\u5185\u5b58\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u5b57\u8282\u6570\u7ec4\uff0cCPU\u6839\u636ePC(Program Counter)\u7684\u503c\u4ece\u5185\u5b58\u4e2d\u63d0\u53d6\u6307\u4ee4\u3002\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b\u8fd0\u884c\u7684\u524d\u63d0\u662f\uff0c\u7a0b\u5e8f\u4ee3\u7801\u548c\u9700\u8981\u8bbf\u95ee\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u3002
CPU\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7684\u901a\u7528\u5b58\u50a8\u53ea\u6709main memory\u548cregisters\u3002\u5bf9registers\u7684\u8bbf\u95ee\u901a\u5e38\u53ef\u4ee5\u5728\u4e00\u4e2aCPU\u65f6\u949f\u5468\u671f\u5b8c\u6210\uff0c\u4f46\u662f\u8bbf\u95ee\u5185\u5b58\u9700\u8981\u591a\u4e2a\u65f6\u949f\u5468\u671f\uff0c\u8fd9\u5c31\u4f1a\u5f15\u8d77\u6307\u4ee4\u7684stall\u3002\u56e0\u4e3a\u6211\u4eec\u4e0d\u60f3\u8981stall\uff0c\u6240\u4ee5\u6211\u4eec\u5728CPU\u4e0a\u8bbe\u8ba1\u4e86\u5b58\u53d6\u66f4\u5feb\u7684\u5185\u5b58cache\u3002
\u8868\u793a\u6e90\u7a0b\u5e8f\u5730\u5740\u7684\u65b9\u6cd5\uff1aAddress Binding
\u6e90\u7a0b\u5e8f\u4e2d\u7684\u5730\u5740\u901a\u5e38\u662f\u7528\u7b26\u53f7\uff08symbolic\uff0c\u4f8b\u5982\u5404\u79cd\u53d8\u91cf\u3001\u51fd\u6570\u540d\u3001\u6c47\u7f16\u4e2d\u7684label\u7b49\uff09\u8868\u793a\u3002\u7f16\u8bd1\u5668\u4f1a\u5c06\u7b26\u53f7\u7ed1\u5230relocatable addresses\uff08\u6bb5\u540d+\u504f\u79fb\u91cf\uff09\u3002\u94fe\u63a5\u5668\u6216\u52a0\u8f7d\u5668\uff08linker/loader\uff09\u4f1a\u5c06relocatable addresses\u7ed1\u5b9a\u5230absolute addresses\u3002\u5f53\u7136\uff0c\u5982\u679c\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u65f6\u5c31\u77e5\u9053\u7a0b\u5e8f\u6240\u5904\u7684\u5185\u5b58\u5730\u5740\uff0c\u5219\u4f1a\u751f\u6210absolute code\u3002
"},{"location":"CS/OS/mem_file/#81-partitioning-strategies","title":"8.1 Partitioning Strategies","text":"\u5728Batch\u7cfb\u7edf\u4e2d\uff0c\u6bcf\u6b21\u53ea\u6709\u4e00\u4e2a\u7a0b\u5e8f\u88ab\u52a0\u8f7d\u5165\u7269\u7406\u5185\u5b58\uff0c\u5e76\u8fd0\u884c\u81f3\u7ed3\u675f\u3002\u5982\u679c\u7a0b\u5e8f\u9700\u8981\u7684\u5b58\u50a8\u7a7a\u95f4\u6bd4\u5185\u5b58\u5927\uff0c\u5219\u5c06\u7a0b\u5e8f\u4e00\u5757\u4e00\u5757\u5207\u5f00
\u4e0eprehistory\u4e0d\u540c\u7684\u662f\uff0c\u73b0\u5728\u9700\u8981\u628a\u591a\u4e2a\u8fdb\u7a0b\u540c\u65f6\u653e\u5165\uff0c\u5e76\u4e14\u652f\u6301\u5feb\u901f\u5207\u6362\u3002\u6700\u7b80\u5355\u7684\u5185\u5b58\u5206\u914d\u65b9\u6cd5\u662f\u5c06\u5185\u5b58\u5207\u6210partition\uff0c\u6bcf\u4e00\u4e2a\u5305\u542b\u4e00\u5757\u8fdb\u7a0b\u3002\u5207\u5206\u7684\u8981\u6c42\u6709
\u5982\u679c\u8fdb\u7a0b\u8bf7\u6c42\u7a7a\u95f4\u6765\u8fd0\u884c\uff0c\u4f46\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\uff0c\u53ef\u4ee5
Fixed Partition\uff1a\u56fa\u5b9apartition\u7684\u5927\u5c0f\u3002\u4f46\u662f\u53ef\u80fd\u9020\u6210\u6d6a\u8d39
Variable Partition\uff1a\u4e0d\u56fa\u5b9apartition\u7684\u5927\u5c0f\u3002OS\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u8868\u8bb0\u5f55\u53ef\u7528\u548c\u5df2\u7528\u7684\u5185\u5b58\u3002\u5b83\u7684\u7f3a\u70b9\u662f\uff1a\u6700\u5f00\u59cb\u5185\u5b58\u662f\u6574\u4e00\u4e2a\u5f88\u5927\u7684\u5185\u5b58\uff08hole\uff09\uff0c\u7ecf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u8fd0\u884c\u540e\uff0c\u51fa\u73b0\u4e00\u7cfb\u5217\u5927\u5c0f\u4e0d\u7b49\u7684\u5b54\uff0c\u8fd9\u4e9b\u5c0f\u7684\u5b54\u90fd\u4e0d\u80fd\u88ab\u5229\u7528\u3002\u79f0\u4e3aexternal fragmentation\u3002
Dynamic Storage-Allocation Problem\uff1a\u6839\u636e\u4e00\u7ec4hole\u6765\u5206\u914d\u5927\u5c0f\u4e3an\u7684\u8bf7\u6c42\uff0c\u79f0\u4e3adynamic storage-allocation problem.
worst-fit\u5bf9\u4e2d\u5c0f\u8fdb\u7a0b\u8f83\u591a\u7684\u60c5\u51b5\u6709\u7528\uff0c\u56e0\u4e3a\u4f7f\u5f97\u5269\u4e0b\u7684\u7a7a\u95f2\u5757\u6bd4\u8f83\u5927\u3002\u4f46\u662f\u5e73\u5747\u60c5\u51b5\u4e0bfirst-fit\u548cbest-fit\u66f4\u597d\u4e00\u70b9\uff0c\u5176\u4e2dfirst-fit\u66f4\u5feb\uff0c\u5176\u5b83\u6ca1\u6709\u4e0ebest-fit\u6709\u660e\u663e\u5dee\u522b\u3002
Protection
\u4fdd\u8bc1\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u4f7f\u7528\u81ea\u5df1\u7684\u5185\u5b58\uff1a\u4f7f\u7528\u4e24\u4e2a\u5bc4\u5b58\u5668\uff0c\u4e00\u4e2abase\uff0c\u4e00\u4e2alimit\uff0c\u5206\u522b\u8868\u793a\u57fa\u5740\u548c\u504f\u79fb\u91cf\u3002\u5f53context switch\u5230\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b or user mode\u60f3\u8981\u8fdb\u884c\u5185\u5b58\u8bbf\u95ee\uff0cCPU\u5c31\u4f1aload\u8fd9\u4e24\u4e2a\u5bc4\u5b58\u5668\u7684\u503c\u3002\u5982\u679c\u975e\u6cd5\u4e86\uff0c\u5c31trap\u6389\uff08\u901a\u5e38\u662fterminate\u8be5\u8fdb\u7a0b\uff09\u3002
\u89e3\u51b3external fragmentation\u6709\u4e24\u4e2a\u601d\u8def\uff1a
\u4e00\u4e2a\u7a0b\u5e8f\u7531\u4e00\u7ec4\u6bb5(unordered set of)\u7ec4\u6210
\u6bcf\u4e2a\u90fd\u662f\u4e00\u4e2a\u6bb5\uff0c\u5728\u5185\u5b58\u4e2d\u4e0d\u4e00\u5b9a\u662f\u6309\u7167\u7528\u6237\u5199\u7684\u987a\u5e8f\u6392\u5217\u7684\uff0c\u987a\u5e8f\u5f88\u968f\u673a\u3002\u8fd9\u4e2a\u987a\u5e8f\u662f\u7f16\u8bd1\u5668\u6784\u5efa\u7684\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u7528\u4e00\u7ec4\u903b\u8f91\u5730\u5740(logical address)\u6216\u8005\u53eb\u865a\u62df\u5730\u5740(virtual address)\u6765\u8bbf\u95ee\u3002
\u903b\u8f91\u5730\u5740 = \u57fa\u5730\u5740 + \u6bb5\u754c
\u6211\u4eec\u6709\u4e00\u4e2asegment table\uff0c\u6bcf\u4e2a\u6761\u76ee\u4ee5segment-number\u7d22\u5f15\uff0c\u5b58\u50a8base\u548climit\uff08\u4e5f\u53ef\u80fd\u8fd8\u5305\u62ec\u6743\u9650\u4f4d\uff09\u3002
\u903b\u8f91\u5730\u5740\u7684\u6620\u5c04\u65b9\u5f0f\u5982\u4e0b\u56fe \u4ece\u903b\u8f91\u5730\u5740\u6620\u5c04\u5230\u7269\u7406\u5730\u5740\u7684\u8fd9\u4e00\u8fc7\u7a0b\u662f\u7531\u786c\u4ef6\u8bbe\u5907MMU\uff08memory-management unit\uff0c\u5185\u5b58\u7ba1\u7406\u5355\u5143\u5b8c\u6210\u7684\uff09\u3002CPU\u4f7f\u7528\u903b\u8f91\u5730\u5740\uff0c\u800c\u5bfb\u5740\u7684\u65f6\u5019\u5c31\u8981\u7528\u7269\u7406\u5730\u5740\u4e86\u3002 \u5206\u6bb5\u662f\u89e3\u51b3external fragmentation\u7684\u4e00\u79cd\u5c1d\u8bd5\uff0c\u56e0\u4e3a\u5b83\u628a\u7a0b\u5e8f\u5206\u6210\u4e86\u5f88\u591a\u6bb5\u3002
\u8fd9\u79cd\u65b9\u6cd5\u597d\u50cf\u4e5f\u88ab\u53eb\u505a\u6742\u5408\u65b9\u6cd5\uff0c\u56e0\u4e3a\u4e0d\u662f\u4e3a\u6574\u4e2a\u5185\u5b58\u7a7a\u95f4\u63d0\u4f9b\u9875\u8868\uff0c\u800c\u662f\u4e3a\u6bcf\u4e2a\u903b\u8f91\u5206\u6bb5\u63d0\u4f9b\u3002
"},{"location":"CS/OS/mem_file/#83-paging","title":"8.3 \u5206\u9875 Paging","text":"\uff08\u8fd9\u4e2a\u5730\u65b9\u6211\u771f\u7684\u771f\u7684\u6ca1\u770b\u61c2\uff0c\u53ef\u4ee5\u7559\u7740\u505alab\u518d\u770b\uff1a\u634f\u5417\u4eca\u5929lab\u5c31\u662f\u8fd9\u4e2a\u73a9\u610f\uff09
\u5141\u8bb8\u8fdb\u7a0b\u7684\u7269\u7406\u5730\u5740\u7a7a\u95f4\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u6848\u3002
\u6211\u4eec\u5c06physical memory\u5207\u6210\u7b49\u5927\u7684\u5757\uff082\u7684\u5e42\uff0c\u901a\u5e38\u4e3a4KB = 2^12 B\uff09\uff0c\u79f0\u4e3aframes\uff08\u5e27\uff09\u3002
\u5c06logical memory\u5207\u6210\u540c\u6837\u5927\u5c0f\u7684\u5757\uff0c\u79f0\u4e3apages\uff08\u9875\uff09\u3002
\u5728paging\u4e2d\u5bf9\u5e94\u5173\u7cfb\u6709\uff1a
MMU\u628alogical address\u7ffb\u8bd1\u6210physical address\u7684\u6b65\u9aa4\uff1a
\u4e3a\u4ec0\u4e48paging\u80fd\u6ee1\u8db3not contiguous\u5462\uff1f\u56e0\u4e3a\u6211\u4eec\u5728PC+1\u6307\u5411\u4e0b\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u53ea\u8981\u5728logical addr\u4e2d\u662f\u4e0b\u4e00\u6761\u6307\u4ee4\u5c31\u53ef\u4ee5\uff0c\u65e0\u6240\u8c13\u8fd9\u4e2alogical addr\u5bf9\u5e94\u7684physical addr\u5728\u54ea\u91cc\u3002\u6211\u4eec\u518d\u56de\u5fc6\u4e00\u4e0blogical addr\u7684\u683c\u5f0f\u5982\u4e0b \u53ef\u89c1d\u662f2^n+1\u65f6 +1 \u662f
\uff08\u5c31\u662f\u4e8c\u8fdb\u5236\u8fdb\u4e86\u4f4d\uff09\u3002\u8fd9\u65f6\u4e00\u4e2apage\u7ed3\u675f\uff0c\u8fdb\u5165\u4e86\u4e0b\u4e00\u4e2apage\u3002logical addr\u4ecd\u7136\u662f\u8fde\u7eed\u7684\u3002
\u786c\u4ef6\u652f\u6301 Hardware Support\uff1apage table\u7684\u786c\u4ef6\u5b9e\u73b0\u6709\u5f88\u591a\u65b9\u6cd5
Translation look-aside buffer (TLB)
\ud83d\udca1 TLB\u548c\u4e00\u822c\u7684cache\u4ec0\u4e48\u533a\u522b\uff1a
TLB\u7528\u4e8e\u5b58\u50a8\u865a\u62df\u5730\u5740\u548c\u7269\u7406\u5730\u5740\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b83\u662fpage table\uff08\u5185\u5b58\u5b50\u96c6\uff09\u7684\u4e00\u4e2acache\u3002
cache\u5b58\u50a8\u6700\u8fd1\u4f7f\u7528\u8fc7\u7684\u6570\u636e\u3002\u5b83\u662f\u6574\u4e2a\u5185\u5b58\u7684cache\u3002
\u6362\u9875\u7684\u7b56\u7565\u6709\uff1aLRU\uff0cround-robin\uff0crandom\u7b49\u3002
TLB with Address-Space Identifier (ASID)
Effective Memory-access Time
hit ratio = \u6ca1\u6709\u53d1\u751fTLB miss\u7684\u6b21\u6570\u7684\u767e\u5206\u6bd4
\u6bcf\u4e00\u6b21\u5185\u5b58\u8bbf\u95ee\u7684\u7528\u65f6\u4e3at\uff0c\u90a3\u4e48TLB hit\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee\u5b57\u8282\u603b\u5171\u7528\u65f6r\uff0cmiss \u7528\u65f62r
\u6709\u6548\u5185\u5b58\u8bbf\u95ee\u65f6\u95f4effective memory-access time EAT = tr + 2t(1-r) = t(2-r)
\u76f8\u6bd4\u76f4\u63a5\u5c06page table\u4fdd\u5b58\u5728\u5bc4\u5b58\u5668\uff0c\u5e73\u5747\uff08\uff1f\uff09\u5185\u5b58\u8bbf\u95ee\u65f6\u95f4\u591a\u4e86 [t(2-r)-t]/t = 1-r\u3002
"},{"location":"CS/OS/mem_file/#lab3","title":"\u591a\u7ea7\u9875\u8868\uff08lab3\u7528\u5230\u7684\uff09","text":"\u53e6\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5206\u6bb5\uff0c\u4f46\u4e5f\u80fd\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5\uff1a\u8bd5\u56fe\u53bb\u6389\u9875\u8868\u4e2d\u6240\u6709\u65e0\u6548\u533a\u57df\uff0c\u800c\u4e0d\u662f\u5c06\u5b83\u4eec\u5168\u90e8\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u3002
\u79f0\u4e3a\u591a\u7ea7\u9875\u8868\uff0c\u5c06\u7ebf\u6027\u8868\u53d8\u6210\u4e86\u7c7b\u4f3c\u6811\u7684\u4e1c\u897f\u3002
\u9996\u5148\u5c06\u9875\u8868\u5206\u6210\u9875\u5927\u5c0f\u7684\u5355\u5143\uff0c\u5982\u679c\u6574\u9875\u7684\u9875\u8868\u9879PTE(page table entry, \u9875\u8868\u6761\u76ee)\u65e0\u6548\uff0c\u5c31\u5b8c\u5168\u4e0d\u5206\u914d\u8be5\u9875\u7684\u9875\u8868\u3002\u4e3a\u4e86\u8ffd\u8e2a\u9875\u8868\u7684\u9875\u662f\u5426\u6709\u6548\uff08\u5982\u679c\u6709\u6548\uff0c\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\uff09\uff0c\u4f7f\u7528\u540d\u4e3a\u9875\u76ee\u5f55\u7684\u65b0\u7ed3\u6784\u3002\u9875\u76ee\u5f55\u544a\u8bc9\u9875\u8868\u7684\u9875\u5728\u54ea\u91cc\uff0c\u6216\u8005\u9875\u8868\u7684\u6574\u4e2a\u9875\u4e0d\u5305\u542b\u6709\u6548\u9875\u3002
\u4f8b\u5b50\uff1a
\u4e0b\u56fe\u4e2d\uff0c\u5de6\u8fb9\u662f\u4e00\u7ea7\u9875\u8868\uff0c\u5c3d\u7ba1\u7b2c\u4e8c\u4e09\u9875\u6ca1\u6709\u6709\u6548\u5730\u5740\uff0c\u4f46\u662f\u4ecd\u7136\u8981\u5206\u914d\u5185\u5b58\u3002
\u53f3\u8fb9\u662f\u4e8c\u7ea7\u9875\u8868\uff0c\u53ef\u4ee5\u770b\u5230\u9875\u8868\u76ee\u5f55\u4ec5\u4e3a\u7b2c\u4e00\u548c\u6700\u540e\u4e00\u9875\u5206\u914d\u5185\u5b58\uff0c\u91ca\u653e\u4e86\u4e2d\u95f4\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u4e0ePTE\u76f8\u4f3c\uff0c\u9875\u8868\u76ee\u5f55\u6709\u4e2aPDE\uff08\u8868\u793a\u6574\u4e2a\u9875\u8868\u91cc\u7684PTE\u7684\u6216\uff09
\u4f18\u70b9
\u7f3a\u70b9
\u6211\u4eec\u8ba8\u8bba\u4e00\u79cd\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684\u7684\u4e00\u90e8\u5206\u53ef\u4ee5\u4e0d\u5728\u5185\u5b58\u91cc\uff0c\u800c\u662f\u88ab\u4ea4\u6362\u5230\u4e00\u4e2a\u5907\u4efd\u5b58\u50a8\uff08backing store\u4e2d\uff09\uff0c\u76f4\u5230\u7ee7\u7eed\u8fd0\u884c\u7684\u65f6\u5019\u518d\u62ff\u56de\u5230\u5185\u5b58\u3002\u8fd9\u79cd\u601d\u60f3\u5f88\u50cfvirtual memory\u3002
\u6bd4\u5982\u5728paging\u673a\u5236\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u53easwap out\u4e00\u4e9bpages\u3002 swapping\u4f1a\u589e\u5927context switching\u7684\u65f6\u95f4\u5f00\u9500\u3002
"},{"location":"CS/OS/mem_file/#9","title":"9. \u865a\u62df\u5185\u5b58","text":"\u4e3a\u4ec0\u4e48\u9700\u8981\u865a\u62df\u5185\u5b58\uff1a\u8fdb\u7a0b\u7684\u4ee3\u7801\u5fc5\u987b\u5728\u5185\u5b58\u4e2d\uff0c\u56e0\u4e3aCPU\u53ea\u6709\u80fd\u529b\u8bbf\u95ee\u5185\u5b58\uff0c\u4e0d\u80fd\u8bbf\u95ee\u78c1\u76d8\u3002\u4f46\u662f\u4e0a\u4e00\u8282\u5f15\u5165\u7684swapping\u673a\u5236\u5141\u8bb8\u6211\u4eec\u628a\u4e00\u90e8\u5206\u5728\u4e3b\u5b58\u4e2d\u6682\u65f6\u7528\u4e0d\u5230\u7684\u5185\u5bb9\u4ea4\u6362\u5230disk\u4e2d\u3002
\u8fd9\u6837\u5c31\u9700\u8981\u6211\u4eec\u5f15\u5165\u903b\u8f91\u5730\u5740\u7a7a\u95f4(logical address space)\u7684\u6982\u5ff5\uff0c\u8981\u5927\u4e8e\u7269\u7406\u5730\u5740\u7a7a\u95f4(physical address space)\uff0c\u5bf9\u5e94\u7684\u9875\u8868\u4f1a\u63d0\u4f9b\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04\u3002
CPU\u8bbf\u95ee\u865a\u62df\u5730\u5740\u65f6\uff0c\u4f1a\u7531MMU\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u7269\u7406\u5730\u5740\u3002\u5982\u679cpage\u4e0d\u5728\u7269\u7406\u5185\u5b58\u4e2d\uff0c\u4f1a\u89e6\u53d1\u4e00\u6b21page fault\uff08exception\uff09\uff0c\u6709\u4e09\u79cd\u53ef\u80fd\u60c5\u51b5\uff1a
\u5728\u4e00\u6761\u6307\u4ee4\u6267\u884c\u671f\u95f4\uff0c\u53ef\u80fd\u89e6\u53d1\u591a\u6b21page fault\uff0c\u76f4\u5230\u89e3\u51b3\u540e\u6210\u529f\u8fd0\u884c\u3002
Kernel address & Userspace address
\u56e0\u4e3a\u6307\u4ee4\u6709privileged\u548cnon-privileged\uff0c\u5730\u5740\u7a7a\u95f4\u4e5f\u5206\u6210\u4e86kernel portion\u548cuser portion\uff0ckernel\u53ea\u80fdprivileged instruction\u8bbf\u95ee\uff0cuser\u90fd\u80fd\u3002\u6240\u6709\u8fdb\u7a0b\u7684kernel portion\u5176\u5b9e\u662f\u540c\u4e00\u5757\u4ee3\u7801\uff0c\u56e0\u4e3a\u6240\u6709\u8fdb\u7a0b\u7528\u5230\u7684\u90fd\u662f\u540c\u4e00\u5757kernel\u3002user portion\u8981\u590d\u5236\u662f\u56e0\u4e3a\u542b\u6709\u7684\u662f\u5404\u4e2a\u8fdb\u7a0b\u7684\u9875\u8868\u3001\u961f\u5217\u7b49\u4e1c\u897f\u3002
"},{"location":"CS/OS/mem_file/#91-lazy-allocation-demand-paging","title":"9.1 Lazy Allocation / Demand Paging","text":"OS\u5728\u5206\u914duser space\u65f6\uff0c\u4f1a\u4f7f\u7528lazy allocation\uff1a\u7528\u6237\u7533\u8bf7\u4e00\u5757\u5185\u5b58\u65f6\uff0cOS\u5e76\u4e0d\u4f1a\u771f\u6b63\u5728\u7269\u7406\u5185\u5b58\u4e2d\u5206\u914d\u5bf9\u5e94\u5185\u5b58\uff0c\u76f4\u5230\u771f\u6b63\u88ab\u8bbf\u95ee\u3002
\u8fd9\u6837\u8bbe\u8ba1\u7684\u539f\u56e0\u662f\u5f88\u591a\u7528\u6237\u7a0b\u5e8f\u7533\u8bf7\u7684\u5185\u5b58\u5927\u5c0f\u901a\u5e38\u6bd4\u771f\u6b63\u8981\u4f7f\u7528\u7684\u5927\u3002\u4f8b\u5982buffer\u3002
"},{"location":"CS/OS/mem_file/#92-copy-on-write","title":"9.2 Copy-on-write","text":"\u5141\u8bb8\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u4f7f\u7528\u540c\u4e00\u4e2a\u7269\u7406\u9875\u6765\u5de5\u4f5c\u3002
"},{"location":"CS/OS/mem_file/#93-page-replacement","title":"9.3 Page Replacement","text":"\u4ece\u5185\u5b58\u4e2d\u4ea4\u6362\u5230\u78c1\u76d8\u53bb\u4e00\u6574\u4e2a\u5f53\u524d\u4e0d\u5728\u4f7f\u7528\u7684frame\u3002
\u6b65\u9aa4\u662f\uff1a - \u627e\u5230\u8fd9\u4e2avictim frame - \u5c06\u5176\u5185\u5bb9\u5199\u5230\u4ea4\u6362\u9875\uff1a\u53ef\u4ee5\u7528\u4e00\u4e2adirty bit\uff0c\u5982\u679c\u6ca1\u6709\u6539\u8fc7\uff0c\u90a3\u5c31\u4e0d\u7528\u5199\u56de\u4e86 - \u4fee\u6539\u9875\u8868\uff08\u548cTLB\uff09\u4ee5\u8868\u793a\u5b83\u4e0d\u5728\u5185\u5b58\u4e2d\u4e86
\u627e\u5230victim frame\u7684\u505a\u6cd5 - Optimal\uff1a\u9009\u62e9\u6700\u957f\u65f6\u95f4\u5185\u4e0d\u518d\u8bbf\u95ee\u7684\u9875\u9762\u6362\u51fa\u3002\u662f\u7406\u60f3\u60c5\u51b5\uff0c\u5b9e\u9645\u5e76\u4e0d\u80fd\u9884\u6d4b\u672a\u6765\u8bbf\u95ee\u60c5\u51b5\u3002\u662f\u4e00\u79cd\u8bc4\u5224\u5176\u5b83\u7b97\u6cd5\u6027\u80fd\u7684\u7406\u8bba\u57fa\u51c6\u3002 - FIFO (First In First Out): \u5f88\u76f4\u89c9\u7684\u505a\u6cd5\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5f88\u591a\u9875\u9762\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u6240\u4ee5\u5148\u8fdbbuffer\u7684\u6709\u53ef\u80fd\u662f\u975e\u5e38\u7ecf\u5e38\u8bbf\u95ee\u7684\u3002\u5b83\u53ef\u80fd\u51fa\u73b0Belady\u2018s Anomaly\uff1a\u7269\u7406\u5e27\u589e\u52a0\uff0c\u5f02\u5e38\u60c5\u51b5\u53cd\u800c\u66f4\u591a\u4e86 - LRU (Least Recently Used)\uff1a\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u7684\u9875\u9762\u3002\u53ef\u4ee5\u6bcf\u4e2a\u9875\u8868\u52a0\u4e00\u4e2acounter\uff0c\u4e5f\u53ef\u4ee5\u7528\u6808\u4fdd\u5b58page numebrs\u3002\u5f00\u9500\u90fd\u633a\u5927\u3002 - LRU-Approximation\uff1a\u5f15\u5165\u4e00\u4e2areference bit\uff0c\u5f53\u88ab\u8bbf\u95ee\u65f6\u7f6e1\uff0cOS\u5b9a\u671f\u628a\u5b83\u7f6e0\u3002\u9700\u8981\u6362\u7684\u65f6\u5019\u5c31\u627e0\uff0c\u8bf4\u660e\u5b83\u5728\u6700\u8fd1\u8fd9\u4e00\u6bb5\u65f6\u95f4\u5185\u90fd\u6ca1\u88ab\u8bbf\u95ee\u8fc7\u3002\u6027\u80fd\u66f4\u597d\u4e86\u3002
"},{"location":"CS/OS/mem_file/#94-allocation-of-frames","title":"9.4 Allocation of Frames","text":"\uff08\u8fd9\u4e2a\u5730\u65b9\u5b8c\u5168\u6ca1\u770b\u61c2\uff09
\u7ed9\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u7684frame\u4e2a\u6570\uff1a
\u66ff\u6362\u65b9\u6cd5
\u5982\u679c\u9700\u8981\u4ece\u6700\u5927\u548c\u6700\u5c0f\u4e4b\u95f4\uff0c\u51b3\u5b9a\u4e00\u4e2a\u8fdb\u7a0b\u80fd\u591f\u4f7f\u7528\u7684page\u603b\u6570\uff0c\u6709\u591a\u79cd\u5206\u914d\u7b97\u6cd5
\u73b0\u4ee3\u8ba1\u7b97\u673a\u90fd\u6709\u591a\u4e2aCPU\uff0c\u6bcf\u4e2aCPU\u6bd4\u5176\u5b83CPU\u66f4\u5feb\u5730\u8bbf\u95ee\u5185\u5b58\u7684\u67d0\u4e9b\u90e8\u5206\u3002\u5982\u679c\u5dee\u5f02\u6bd4\u8f83\u660e\u663e\uff0c\u79f0\u8fd9\u79cd\u7cfb\u7edf\u4e3a\u975e\u5747\u5300\u5185\u5b58\u8bbf\u95ee\uff08NUMA\uff0cnon-uniform memory access\uff09\u7cfb\u7edf\u3002
"},{"location":"CS/OS/mem_file/#95-thrashing","title":"9.5 Thrashing","text":"\u5982\u679c\u8fdb\u7a0b\u53ef\u7528\u7684\u5e27\u8f83\u5c11\uff08\u5c11\u4e8e\u9891\u7e41\u8bbf\u95ee\u7684\u9875\u9762\u6570\u76ee\uff09\uff0c\u90a3\u4e48\u9891\u7e41\u51fa\u73b0page fault\u3002\u540c\u4e00\u4e2apage\u88ab\u9891\u7e41\u6362\u5165\u6362\u51fa\uff0c\u4ee5\u6ee1\u8db3\u8fd0\u884c\u7684\u8981\u6c42\u3002\u8fd9\u79cd\u9ad8\u5f3a\u5ea6\u9875\u9762\u8c03\u5ea6\u53eb\u6296\u52a8\uff08thrashing\uff09\uff0c\u5176\u9875\u9762\u8c03\u5ea6\u7528\u65f6\u751a\u81f3\u53ef\u80fd\u5927\u4e8e\u6267\u884c\u65f6\u95f4\u3002
"},{"location":"CS/OS/mem_file/#96-kernel-memory-allocation","title":"9.6 Kernel Memory Allocation","text":"kernel\u4e2d\u7684\u5f88\u591a\u6570\u636e\u7ed3\u6784\u5927\u5c0f\u533a\u5206\u6bd4\u8f83\u5927\uff0c\u5c0f\u7684\u53ef\u80fd\u4f1a\u5c0f\u4e8e\u4e00\u4e2apage\uff0c\u56e0\u6b64kernel\u7684\u8bbe\u8ba1\u5e94\u5f53\u5c3d\u91cf\u8282\u7701\u5185\u5b58\uff0c\u52aa\u529b\u51cf\u5c11\u788e\u7247\u3002\u539f\u56e0\u662f
\u4e24\u8005\u5bf9\u7269\u7406\u5185\u5b58\u7684\u8981\u6c42\u90fd\u6bd4\u8f83\u4e25\u683c
\u5206\u914d\u65b9\u6cd5
\u73b0\u4ee3\u8ba1\u7b97\u673a\u7684\u5927\u90e8\u5206\u4e8c\u7ea7\u5b58\u50a8\u7531hard disk drives (HDDs) \u548c nonvolatile memory (NVM) devices \u63d0\u4f9b\u3002
\u8bfe\u672c\u91cc\u8ba4\u4e3aNVM\uff08electronic\uff09\u4e0d\u5305\u542bHDD\uff08mechanical\uff09
HDD \u7ed3\u6784
\u53c2\u6570
NVM Devices
\u6bd4HDD\u66f4\u53ef\u9760\uff0c\u66f4\u5feb\uff0c\u66f4\u8d35\uff0c\u5bff\u547d\u77ed\uff0c\u5bb9\u91cf\u66f4\u5c0f
"},{"location":"CS/OS/mem_file/#102-hdd-scheduling","title":"10.2 \u78c1\u76d8\u8c03\u5ea6 HDD Scheduling","text":"\u4e3b\u8981\u4e3a\u4e86\u4f18\u5316\u4e24\u4e2a\u53c2\u6570
\u4e00\u822c\u4f1a\u8003\u8651minimize seek time\uff0c\u56e0\u4e3arotational latency\u4e00\u822c\u7ba1\u4e0d\u5230
First-Come First-Served (FCFS)
Advantages
Disadvantages:
Shortest seek time first (SSTF)
\u603b\u662f\u9009\u62e9\u8ddd\u79bb\u5f53\u524d\u6700\u8fd1\u7684request\u3002\u4e0d\u4e00\u5b9a\u6700\u597d
cannot calculate seek time in advance
high variance
\u53ef\u80fd\u5bfc\u81f4starvation
SCAN / Elevator algorithm
\u975e\u5e38\u5f62\u8c61\uff0c\u4e00\u76f4\u5f80\u4e00\u4e2a\u65b9\u5411\u8d70\u4e0d\u56de\u5934\uff0c\u76f4\u5230\u78b0\u5230\u8fb9\u754c\uff0c\u518d\u8fd4\u56de
long waiting time for requests that are just visited.
C-SCAN
\u4e0d\u662f\u8fb9\u8fd4\u56de\u8fb9\u626b\uff0c\u800c\u662f\u76f4\u63a5\u8fd4\u56de\u5f00\u5934
provides more uniform wait time than SCAN
LOOK / C-LOOK
\u5728 SCAN / C-SCAN \u7684\u57fa\u7840\u4e0a\uff0c\u53ea\u8d70\u5230\u6700\u5927/\u6700\u5c0f\u7684request\u7f16\u53f7\u5c31\u8fd4\u56de\uff0c\u800c\u4e0d\u662f\u8d70\u5230section\u7684\u5934\u3002
\u600e\u6837\u9009\u62e9scheduling algorithm\uff1a\u4e00\u822c\u9009\u62e9SSTF\uff0c\u5f53IO\u8d1f\u8377\u6bd4\u8f83\u5927\u65f6\uff0c\u9009\u62e9 LOOK / C-LOOK
"},{"location":"CS/OS/mem_file/#103","title":"10.3 \u78c1\u76d8\u7ba1\u7406","text":"\u78c1\u76d8\u683c\u5f0f\u5316\u6b65\u9aa4
boot block
\u5728\u521a\u6253\u5f00\u7535\u6e90\u6216\u91cd\u542f\u65f6\uff0c\u4e00\u4e2a\u81ea\u4e3e\uff08bootstrap\uff09\u7a0b\u5e8f\u4f1a\u521d\u59cb\u5316\u7cfb\u7edf\u7684\u5404\u4e2a\u90e8\u5206\uff0c\u5982CPU\u5bc4\u5b58\u5668\u3001\u8bbe\u5907\u63a7\u5236\u5668\u3001\u5185\u5b58\uff0c\u7136\u540e\u627e\u5230OS\u5185\u6838\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\uff0c\u4ece\u800c\u8fd0\u884cOS\u3002
\u4e00\u822cbootstrap\u7684\u542f\u52a8\u7a0b\u5e8ftiny bootstrap loader program\u5b58\u5728ROM\uff0c\u5b83\u5728\u78c1\u76d8\u4e2d\u7684boot partition\u628abootstrap\u7a0b\u5e8fload\u8fdb\u6765\u3002
"},{"location":"CS/OS/mem_file/#104-raid","title":"10.4 RAID","text":"\u78c1\u76d8\u5197\u4f59\u9635\u5217\uff08redundant array of independent disk, RAID\uff09\u6280\u672f\u3002
\u5b9a\u4e49\u597d\u50cf\u662f\u4e00\u4e2a\u62e5\u6709\u5927\u91cf\u78c1\u76d8\u7684\u7cfb\u7edf\uff0c\u6765\u6539\u5584\u6570\u636e\u7684\u8bfb\u5199\u901f\u7387\uff08\u56e0\u4e3a\u53ef\u4ee5\u5e76\u884c\uff09\uff0c\u4e14\u53ef\u9760\uff08\u4f7f\u7528\u5197\u4f59\u6765\u964d\u4f4e\u51fa\u73b0\u9519\u8bef\u7684\u671f\u671b\uff09\u3002
"},{"location":"CS/OS/mem_file/#11-io","title":"11. IO","text":""},{"location":"CS/OS/mem_file/#111","title":"11.1 \u65b9\u5f0f","text":"IO\u7cfb\u7edf\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u5c06\u4e0d\u540c\u7684IO\u8bbe\u5907\u7684\u5de5\u4f5c\u65b9\u5f0f\u5c01\u88c5\u5230\u4e00\u4e9b\u7c7b\u4e2d\uff0c\u4ece\u800c\u5f62\u6210\u8f83\u5c11\u7684\u901a\u7528\u7c7b\u578b\uff0c\u4e3a\u5e94\u7528\u7a0b\u5e8f\u9690\u85cf\u786c\u4ef6\u7684\u5177\u4f53\u5dee\u5f02\u3002
\u540c\u65f6\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u652f\u6301\u5e94\u7528\u7a0b\u5e8f\u900f\u660e\u5730\u5411\u4e00\u4e2a\u8bbe\u5907\u9a71\u52a8\u5668\u4f20\u8f93\u4efb\u610f\u6570\u636e\u3002\u5728UNIX\u4e2d\uff0c ioctl()
\u7cfb\u7edf\u8c03\u7528\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002\u8fd9\u4e00\u7cfb\u7edf\u8c03\u7528\u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08file descriptor\uff09\u6765\u786e\u5b9a\u4e00\u4e2a\u8bbe\u5907\uff0c\u56e0\u4e3aUNIX\u4e2d\u8bbe\u5907\u53ef\u4ee5\u901a\u8fc7\u6587\u4ef6\u7684\u65b9\u5f0f\u8bbf\u95ee\u3002
\u6587\u4ef6\u7cfb\u7edf\uff08file system\uff09\u662f\u4e3a\u4e86\u7ed9\u7528\u6237\u63d0\u4f9bdisk\u7684\u903b\u8f91\u89c6\u56fe\u3002
\u5e38\u89c1\u7684\u6587\u4ef6\u5c5e\u6027\u5b57\u6bb5
\u8fd9\u4e9b\u4fe1\u606f\u5b58\u5728\u76ee\u5f55\u7ed3\u6784\u91cc
\u6587\u4ef6\u64cd\u4f5c
\u6587\u4ef6\u6253\u5f00: \u6253\u5f00\u6587\u4ef6\u8868\uff08open-file table\uff09\uff0cfile-open count
\u6587\u4ef6\u9501\uff08file lock\uff09\uff1a\u7c7b\u4f3c\u4e8ereader-writer lock\u3002\u5206\u5171\u4eab\u9501\uff08shared lock\uff09\uff0c\u72ec\u5360\u9501\uff08exclusive lock\uff09\u3002\u5206\u5f3a\u5236\u9501\u5b9a\uff08mandatory lock\uff09\u548c\u5efa\u8bae\u9501\u5b9a\uff08advisory lock\uff09\u3002
\u6587\u4ef6\u7c7b\u578b\uff1a\u6587\u4ef6\u6269\u5c55\u540d\uff0c\u6216\u6587\u4ef6\u5934\u7684magic number
\u6587\u4ef6\u7ed3\u6784\uff1a
directory structure \u53ef\u4ee5\u6784\u5efa\u5728\u591a\u4e2avolume\u4e0a\uff0c\u8fd9\u4e9b\uff08\u522b\u7684\uff1f\uff09volume\u5fc5\u987b\u5148\u6302\u8f7d\uff08mount\uff09\u5230\u6587\u4ef6\u7cfb\u7edf\u7684\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u4f4d\u7f6e\u79f0\u4e3a\u6302\u8f7d\u70b9\uff08mount point\uff09\u3002
"},{"location":"CS/OS/mem_file/#125","title":"12.5 \u4fdd\u62a4","text":"Access Control List (ACL): \u6307\u5b9a\u6bcf\u4e2a\u7528\u6237\u53ca\u5141\u8bb8\u7684\u8bbf\u95ee\u7c7b\u578b\u3002
e.g. in Linux
\u6587\u4ef6\u7cfb\u7edf\u901a\u5e38\u5206\u5f88\u591a\u5c42
\u4e0a\u8ff0\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7528\u5230\u7684\u7279\u6b8a\u6570\u636e\u7ed3\u6784\u6709
In disk structures:
File control block (FCB) (per file)\uff1a\u4fdd\u5b58name, ownership, permissions, ref count, timestamps, pointers to data blocks on disk. \u6bcf\u4e2aFCB\u6709\u4e2a\u552f\u4e00\u6807\u8bc6\u53f7\uff0c\u4e0e\u76ee\u5f55\u6761\u76ee\u76f8\u5173\u8054\u3002
\u5728unix\u4e2dFCB\u53ebinode
\u5728NTFS\u4e2d\uff0c\u6bcf\u4e2aFCB\u662f\u4e00\u4e2a\u53ebmaster file table\u7684\u7ed3\u6784\u7684\u4e00\u884c\u3002 boot control block (per volume):
volume control block (per volume):
directory (per FS):
"},{"location":"CS/OS/mem_file/#133-vfs","title":"13.3 VFS \u865a\u62df\u6587\u4ef6\u7cfb\u7edf","text":"OS\u53ef\u4ee5\u540c\u65f6\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u6587\u4ef6\u7cfb\u7edf\u3002\u5b9a\u4e49\u4e86\u4e00\u5957\u901a\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u8bbf\u95ee\u63a5\u53e3\uff0copen(), read(), write(), close() \u548c file descriptiors \u7b49\uff0c\u4e0e\u5177\u4f53\u7684\u5b9e\u73b0\u5206\u79bb\u3002VFS\u8d1f\u8d23\u5bf9\u5e94\u8fd9\u4e9b\u63a5\u53e3\u548c\u5177\u4f53\u7684\u51fd\u6570\u6307\u9488\u3002
"},{"location":"CS/OS/mem_file/#134","title":"13.4 \u76ee\u5f55\u5b9e\u73b0","text":"\u4fdd\u5b58file name \u5230 FCB \u7684\u6620\u5c04\u5173\u7cfb\u3002
\u6587\u4ef6\u4fdd\u5b58\u5728disk blocks\u4e0a\u7684\u7b56\u7565\u3002
contiguous allocation: \u6bcf\u4e2a\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u5360\u6709\u7684blocks\u662f\u8fde\u7eed\u7684\u3002\u4f1a\u9020\u6210\u788e\u7247\u3002\u6587\u4ef6\u662f\u53ef\u6269\u5c55\u7684\u3002\u53ef\u4ee5\u5b9e\u73b0\u786e\u5b9a\u6bcf\u4e2a\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f\u3002\u4e5f\u53ef\u4ee5\u5f53\u7a7a\u95f4\u4e0d\u591f\u65f6\u7ef4\u62a4\u4e00\u4e2a\u6307\u9488\uff0c\u8bb0\u5f55\u6dfb\u52a0\u7684\u8fde\u7eed\u7a7a\u95f4\uff08extent\uff09\u7684\u4fe1\u606f\u3002\u76ee\u5f55\u9700\u8981\u8bb0\u5f55\u6bcf\u4e2a\u6587\u4ef6\u7684\u8d77\u6b62\u5730\u5740\u3002
linked allocation: \u6bcf\u4e2ablock\u8bb0\u5f55\u4e0b\u4e00\u5757\u7a7a\u95f4\u7684\u5730\u5740\uff0c\u6709\u70b9\u50cf\u94fe\u8868\u3002\u76ee\u5f55\u5219\u53ea\u8bb0\u5f55\u8d77\u6b62\u5730\u5740\u3002
indexed allocation: \u7ed9\u6bcf\u4e2a\u6587\u4ef6\u8bb0\u5f55\u4e00\u4e2a\u7d22\u5f15\u5757 (index block)\uff0c\u8bb0\u5f55\u6bcf\u4e2a\u6587\u4ef6\u7684\u7b2ci\u4e2a\u5757\u5728\u78c1\u76d8\u7684\u54ea\u4e2a\u5730\u65b9\u3002\u76ee\u5f55\u53ea\u9700\u8981\u4fdd\u5b58\u7d22\u5f15\u5757\u5728\u54ea\u91cc\u3002
"},{"location":"CS/OS/mem_file/#136","title":"13.6 \u7a7a\u95f2\u7a7a\u95f4\u7ba1\u7406","text":"\u53ef\u4ee5\u7528bitmap\uff0c\u75281\u6807\u8bb0\u7a7a\u95f2\u7684block\u3002\u4e3a\u4e86\u51cf\u5c11bitmap\u5360\u7528\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u4ee5cluster\u4e3a\u5355\u4f4d\u8bb0\u5f55\u3002
\u53ef\u4ee5\u5c06free space\u7528\u94fe\u8868\u94fe\u63a5\uff0c\u4f46\u8bbf\u95ee\u6548\u7387\u8f83\u4f4e\u3002
\u53ef\u4ee5\u5f15\u5165grouping\uff0c\u7ef4\u62a4\u82e5\u5e72\u4e2ablock\u5f62\u6210\u7684\u94fe\u8868\uff0c\u6bcf\u4e2ablock\u4fdd\u5b58\u82e5\u5e72\u7a7a\u95f2\u5757\u7684\u5730\u5740\u3002
counting\uff1a\u7ef4\u62a4\u8fde\u7eed\u7a7a\u95f2\u5757\u7684\u94fe\u8868\uff0c\u5373\uff0c\u94fe\u8868\u7684\u6bcf\u4e2a\u8282\u70b9\u662f\u8fde\u7eed\u7684\u7a7a\u95f2\u5757\u7684\u9996\u5757\u6307\u9488\u548c\u8fde\u7eed\u7684\u957f\u5ea6\u3002
"},{"location":"CS/OS/overview/","title":"OS Lecture Overview","text":""},{"location":"CS/OS/overview/#_1","title":"\u6210\u7ee9","text":"\u6559\u6750\uff1a\u53ea\u4e0a1-13
"},{"location":"CS/OS/overview/#1-overview","title":"1. \u64cd\u4f5c\u7cfb\u7edfoverview","text":""},{"location":"CS/OS/overview/#11","title":"1.1 \u57fa\u672c\u6982\u5ff5","text":""},{"location":"CS/OS/overview/#12","title":"1.2 \u64cd\u4f5c\u7cfb\u7edf\u5386\u53f2/\u7ed3\u6784\u7684\u79cd\u7c7b","text":"\u9664\u4e86kernel\u5916\uff0cOS\u8fd8\u5305\u542b\u4e00\u4e9bsystem programs\u8f85\u52a9kernel\u5de5\u4f5c\u3002\u5176\u5b83\u7a0b\u5e8f\u4e0d\u5c5e\u4e8eOS\uff0c\u88ab\u79f0\u4e3aapplication programs \u21d2 \u603b\u4e4b\uff0cOS\u662f\u8f6f\u4ef6\u4e2d\u6700\u57fa\u7840\u7684\u90e8\u5206\uff0c\u7528\u4ee5\u63a7\u5236\u548c\u7ba1\u7406\u7cfb\u7edf\u8d44\u6e90\uff0c\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u8ba1\u7b97\u673a\u3002
"},{"location":"CS/OS/overview/#13","title":"1.3 \u4e2d\u65ad","text":"\u6279\u5904\u7406\u7cfb\u7edf\u662f\u6700\u5bb9\u6613\u7406\u89e3\u7684\uff1a\u6bcf\u4e2a\u7a0b\u5e8f\u50cf\u4e00\u4e2a\u51fd\u6570\u4e00\u6837\u88abOS\u8c03\u7528\u3002
\u5176\u5b83\u7cfb\u7edf\uff1a\u7528\u5230\u4e2d\u65ad\uff08interrupt\uff09\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u90fd\u662f\u4e2d\u65ad\u9a71\u52a8\u7684
CPU\u786c\u4ef6\u6709\u4e00\u6761\u88ab\u79f0\u4e3ainterrupt-request line\u7684\u7ebf\u8def\uff0cCPU\u6bcf\u6267\u884c\u4e00\u6761\u6307\u4ee4\u540e\u90fd\u8981\u68c0\u6d4b\u4e00\u6b21\u3002\u5f53CPU\u4fa6\u6d4b\u5230\u4e00\u4e2a\u8bbe\u5907\u63a7\u5236\u5668\u5728\u8fd9\u6761\u7ebf\u8def\u4e0a\u53d1\u51fa\u7684\u4fe1\u53f7\u65f6\uff0c\u4f1a\u8bfb\u53d6interrupt number\u5e76\u4ee5\u6b64\u4f5c\u4e3ainterrupt vector\u4e2d\u7684index\u6765\u8df3\u8f6c\u5230\u5bf9\u5e94\u7684interrupt-handler routine\u3002
\u4e2d\u65ad\u5411\u91cf\u8868\uff08interrupt vector\uff09\u7528\u6765\u51cf\u5c11\u786e\u5b9a\u4e2d\u65ad\u670d\u52a1\u65f6\u7684\u67e5\u627e\u6b21\u6570\uff0c\u5373\u901a\u8fc7\u968f\u673a\u8bbf\u95ee\u800c\u4e0d\u662f\u904d\u5386\u7684\u65b9\u5f0f\u627e\u5230\u5904\u7406\u7a0b\u5e8f\u3002
\u5728\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u9700\u8981\u4e00\u4e9b\u66f4\u590d\u6742\u7684\u4e2d\u65ad\u5904\u7406\u529f\u80fd\uff1a
\u5728\u73b0\u4ee3\u7684\u8ba1\u7b97\u673a\u786c\u4ef6\u4e2d\uff0c\u8fd9\u4e9b\u7279\u65b0\u7531CPU\u548cinterrupt-controller hardware\u5b9e\u73b0\u3002
\u5927\u591a\u6570CPU\u6709\u4e24\u6761interrupt-request line
\u5728\u8c03\u7528\u51fd\u6570\u65f6\u9700\u8981\u4fdd\u5b58PC\u7b49\u73b0\u573a\u72b6\u6001\uff0c\u6267\u884c\u4e2d\u65ad\u65f6\u4e5f\u8981\u4fdd\u5b58\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4f4e\u7ea7\u4e2d\u65ad\u8981\u88ab\u9ad8\u7ea7\u4e2d\u65ad\u6253\u65ad\uff0c\u4f46\u662f\u4fdd\u5b58\u548c\u56de\u590d\u73b0\u573a\u72b6\u6001\u7684\u8fc7\u7a0b\u4e0d\u5e94\u5f53\u88ab\u6253\u65ad\u3002 \u8ba1\u65f6\u5668\u4e0e\u5206\u65f6\u7cfb\u7edf\u7684\u5b9e\u73b0\uff1a
\u5f53\u64cd\u4f5c\u7cfb\u7edf\u5c06CPU\u7684\u63a7\u5236\u6743\u4ea4\u7ed9\u4e00\u4e2a\u7a0b\u5e8f\u524d\uff0c\u4f1a\u8bbe\u5b9a\u597d\u4e00\u4e2a\u8ba1\u65f6\u5668timer\u3002timer\u901a\u8fc7\u4e00\u4e2a\u65f6\u949f\u548c\u4e00\u4e2a\u8ba1\u6570\u5668\u5b9e\u73b0\uff0c\u5f53\u8ba1\u6570\u5668\u7684\u503c\u4e3a0\u65f6\uff0c\u5c31\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\uff0c\u8fd9\u65f6\u63a7\u5236\u6743\u4ea4\u7ed9\u4e86OS\u3002\u53ef\u4ee5\u9632\u6b62\u7a0b\u5e8f\u6267\u884c\u65f6\u95f4\u8fc7\u957f\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u5206\u65f6\u7cfb\u7edf\u3002
"},{"location":"CS/OS/overview/#14","title":"1.4 \u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\uff0c\u7cfb\u7edf\u8c03\u7528","text":"Dual-mode & multimode
OS\u548c\u7528\u6237\u5171\u4eab\u8ba1\u7b97\u673a\u7684\u786c\u4ef6\u548c\u8f6f\u4ef6\u3002\u56e0\u6b64\uff0c\u4e00\u4e2a\u9519\u8bef\u7684\u7a0b\u5e8f\u53ef\u80fd\u5bfc\u81f4\u6574\u4e2a\u7cfb\u7edf\u5d29\u6e83\uff0c\u6216\u8005\u4f7f\u5f97\u5176\u5b83\u7528\u6237\u7684\u6570\u636e\u751a\u81f3OS\u672c\u8eab\u88ab\u4fee\u6539\u3002\u56e0\u6b64OS\u7684\u8bbe\u8ba1\u8981\u4fdd\u8bc1\u4e00\u4e2a\u9519\u8bef\u7684\u7a0b\u5e8f\u4e0d\u4f1a\u9020\u6210\u5176\u5b83\u7a0b\u5e8f\u7684\u9519\u8bef\u8fd0\u884c\u3002
\u7cfb\u7edf\u4ee3\u7801\u80fd\u8fd0\u884c\u7684\u6307\u4ee4\uff1aprivileged instructions
CPU\u6709\u4e00\u4e2amode bit\uff0c\u503c\u4e3a0\uff0c\u8868\u793a\u5f53\u524d\u5904\u4e8ekernel mode\uff08supervisor/system/privileged mode\uff09\uff0c\u503c\u4e3a1\u8868\u793a\u5904\u4e8euser mode\u3002\u6240\u6709\u7684interrupt handler\u90fd\u8fd0\u884c\u5728kernel mode\u3002
\u5982\u679c\u7528\u6237\u771f\u7684\u60f3\u6267\u884c\u7279\u6743\u6307\u4ee4\uff0c\u53ef\u4ee5\u7528system call\uff0c\u7531OS\u4ee3\u4e3a\u5b8c\u6210\u3002
OS\u80fd\u591f\u6267\u884c\u7684system call:
Process control - create process, terminate process - load, execute - get process attributes, set process attributes - wait event, signal event - allocate and free memory
File management - create file, delete file - open, close - read, write, reposition - get file attribute, set file attribute
Device management - request device, release device - read, write, reposition - get file attributes, set device attributes - logically attach or detach devices
Information maintenance - get time or date, set time or date - get system data, set system data - get process, file, or device attributes - set process, file, or device attributes
Communications - create, delete communication connection - send, receive messages - transfer status information - attach or detach remote devices
Protection - get file permissions - set file permissions
\u56e0\u6b64\u5f53\u53d1\u751f\u4e2d\u65ad\u3001system call\u3001\u9519\u8bef\uff08\u9664\u4ee50\uff0c\u6216\u8bbf\u95ee\u672a\u77e5\u6307\u4ee4\uff09\u7b49\u60c5\u51b5\u65f6\uff0c\u4f1a\u53d1\u751fuser mode\u5230
kernel mode\u7684\u8f6c\u6362
"},{"location":"CS/OS/process_syn/","title":"OS Lecture \u8fdb\u7a0b\u4e0e\u540c\u6b65","text":""},{"location":"CS/OS/process_syn/#2-process","title":"2. \u8fdb\u7a0b Process","text":""},{"location":"CS/OS/process_syn/#21","title":"2.1 \u7ec4\u6210","text":"\u8fdb\u7a0bprocess\uff08=\u4f5c\u4e1ajob\uff09\u662f\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u591a\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u5bf9\u5e94\u540c\u4e00\u4e2a\u7a0b\u5e8f\u3002\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684OS\u4e2d\u4f1a\u6709\u591a\u4e2a\u8fdb\u7a0b\uff0c\u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u6267\u884c\u8fc7\u7a0b\uff0c\u662fOS\u5206\u914d\u8d44\u6e90\u7684\u57fa\u672c\u5355\u4f4d\u3002
\u8fdb\u7a0b\u7684\u7ec4\u6210\uff1a\u4e00\u4e2a\u8fdb\u7a0b\u5305\u62ec - code or text - \u5373\u7a0b\u5e8f\u4ee3\u7801\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\u524d\u4ee5executable file\u7684\u5f62\u5f0f\u5b58\u50a8\u5728disk\u4e2d - program counter - PC\uff0c\u6307\u5411\u4e0b\u4e00\u4e2a\u8981\u8fd0\u884c\u7684\u6307\u4ee4 - counter of the processor\u2019s registers - \u5728\u8fdb\u7a0b\u4e4b\u95f4\u5207\u6362\u65f6\uff0c\u9700\u8981\u4fdd\u5b58\u5bc4\u5b58\u5668\u7684\u503c\u4ee5\u4fbf\u4e0b\u6b21\u56de\u5230\u8be5\u8fdb\u7a0b\u65f6\u7ee7\u7eed\u8fd0\u884c - run time stack - \u5728ICS\u548c\u6c47\u7f16\u4e2d\u5b66\u4e60\u8fc7\u76f8\u5173\u5185\u5bb9\uff0c\u5176\u4e2d\u7684\u6761\u76ee\u79f0\u4e3aactivation records\uff08stack frames\uff09 - \u7531\u7528\u6237\u4ee3\u7801\u63a7\u5236\uff08\u7f16\u8bd1\u65f6\u5b8c\u6210\u5173\u4e8e\u6808\u7684\u76f8\u5173\u8c03\u7528\uff09\uff0c\u5728\u8c03\u7528\u51fd\u6570\u65f6\u6682\u65f6\u5b58\u50a8\u4e00\u4e9b\u6570\u636e\uff0c\u5982local variables, return address, return values, state of registers, parameters\u7b49 - data section - global variables - heap - dynamically allocated memory
"},{"location":"CS/OS/process_syn/#22","title":"2.2 \u8fdb\u7a0b\u7684\u72b6\u6001","text":"\u8fdb\u7a0b\u5728\u6267\u884c(execute)\u65f6\u4f1a\u6539\u53d8\u72b6\u6001(state)\uff1a \u4e00\u4e2a\u5904\u7406\u5668\uff0c\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5running\uff0c\u66f4\u591a\u7684\u5904\u4e8eready\u6216waiting\u72b6\u6001
"},{"location":"CS/OS/process_syn/#23-process-control-block-pcb-aka-task-control-block","title":"2.3 \u8fdb\u7a0b\u63a7\u5236\u5757Process Control Block (PCB, aka. task control block)","text":"\u8868\u793a\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u6709\u4e14\u4ec5\u6709\u4e00\u4e2aPCB
PCB\u5305\u542b\u7684\u5173\u4e8e\u5f53\u524d\u8fdb\u7a0b\u7684\u4fe1\u606f\uff1a - process state \u8fdb\u7a0b\u72b6\u6001 - program counter - CPU registers \u8fdb\u7a0b\u76f8\u5173\u7684\u5bc4\u5b58\u5668\u7684\u503c - CPU scheduling information, properties, scheduling queue pointers, etc. - Memory-management information - Accounting information, CPU \u4f7f\u7528\u65f6\u95f4\uff0c\u65f6\u95f4\u671f\u9650\uff0c\u8bb0\u8d26\u6570\u636e\u7b49 - IO status information, \u5206\u914d\u7ed9\u8fdb\u7a0b\u7684IO\u8bbe\u5907\u5217\u8868\uff0c\u6253\u5f00\u6587\u4ef6\u5217\u8868\u7b49
PCB\u7ed3\u6784\u793a\u610f\u56fe \u4e0d\u540c\u7684\u7cfb\u7edf\u53ef\u80fd\u6709\u4e0d\u540c\u7684PCB\u3002Linux\u4e2d\u7684\u8fdb\u7a0b\u7528\u7ed3\u6784\u4f53task_struct\u5b58\u50a8\u3002
"},{"location":"CS/OS/process_syn/#24-pid","title":"2.4 \u8fdb\u7a0b\u7684\u521b\u5efa\uff0cpid","text":"OS\u901a\u8fc7\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff08process identifier, pid\uff09\u8bc6\u522b\u8fdb\u7a0b\u3002\u4e00\u4e2a\u8fdb\u7a0b\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b\uff0c\u5219\u5b83\u6210\u4e3a\u7236\u8fdb\u7a0b\uff0c\u65b0\u8fdb\u7a0b\u79f0\u4e3a\u5b50\u8fdb\u7a0b\u3002
\u7236\u8fdb\u7a0b\u7684pid\u79f0\u4e3a\u5b50\u8fdb\u7a0b\u7684ppid\uff08parent\u2019s pid\uff09\u2192 \u5f62\u6210\u8fdb\u7a0b\u6811\uff08process tree\uff09 \u5f53\u5b50\u8fdb\u7a0b\u521b\u5efa\u65f6\uff0c\u9700\u8981\u7684\u8d44\u6e90\uff08CPU\u65f6\u95f4\u3001\u5185\u5b58\u3001\u6587\u4ef6\u3001IO\u8bbe\u5907\u7b49\uff09\u53ef\u4ee5\u6765\u81eaOS\u4e5f\u53ef\u4ee5\u7ee7\u627f\uff08\u5171\u4eab\uff09\u81ea\u7236\u8fdb\u7a0b\u3002
UNIX\u7cfb\u7edf\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528fork()\u521b\u5efa\u65b0\u8fdb\u7a0b\uff0c\u76f8\u5f53\u4e8e\u62f7\u8d1d\u4e86\u4e00\u4efd\u7236\u8fdb\u7a0b\uff0c\u53ea\u6539\u53d8pid\u548cppid\uff0c\u7136\u540e\u628a\u5b50\u8fdb\u7a0b\u5f53\u524d\u5185\u5b58\u4f7f\u7528\u8bb0\u5f55\u8bbe0\u3002fork()\u7ed9\u7236\u8fdb\u7a0b\u8fd4\u56de\u503c\u662f\u5b50\u8fdb\u7a0b\u7684pid\uff0c\u7ed9\u5b50\u8fdb\u7a0b\u8fd4\u56de0\u3002
\u4ee3\u7801\u6bb5\uff1acreating a separate process using the UNIX fork() system call.
#include <sys/types.h>\n#include <stdio.h>\n#include <unist.h>\nint main()\n{\npid_t pid;\n/* fork a child process */\npid = fork();\nif (pid < 0){\n/* error occurred */\nfprintf(stderr, \"Fork Failed\");\nreturn 1;\n}\nelse if (pid == 0) {\n/* child process */\nexeclp(\"/bin/ls\", \"ls\", NULL);// \u5bf9\u4e8e\u7528\u6237\u7ed9\u51fa\u7684\u6307\u5b9a\u6587\u4ef6\u540d\uff0c\u7a0b\u5e8f\u4f1a\u5728\u5f53\u524dPATH\u73af\u5883\u53d8\u91cf\u4e0b\u641c\u7d22\n}\nelse {\n/* parent process */\n/* parent will wait for the child to complete */\nwait(NULL);\nprintf(\"child complete\");\n}\nreturn 0;\n}\n
fork() \u5982\u4f55\u5bf9\u7236\u8fdb\u7a0b\u548c\u5b50\u8fdb\u7a0b\u8fd4\u56de\u4e0d\u540c\u7684\u503c\uff1a\u5f53\u521b\u5efa\u65b0\u8fdb\u7a0b\u65f6\uff0c\u7236\u8fdb\u7a0b\u53ef\u4ee5
\u5b50\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u6709\u53ef\u80fd
\u4e3a\u4ec0\u4e48\u8981\u62f7\u8d1d\u4e00\u4efd\uff0c\u6709\u7684\u5b50\u8fdb\u7a0b\u4e0d\u4f1a\u7528copy\u7684\u5730\u5740\u3002\u6240\u4ee5\u90e8\u5206UNIX\u5f15\u5165\u4e86copy-on-write\u673a\u5236\uff0c\u5373\u5c06\u5730\u5740\u7a7a\u95f4\u7684\u590d\u5236\u63a8\u8fdf\u5230\u9700\u8981\u5199\u5165\u7684\u65f6\u5019\u518d\u8fdb\u884c\u3002
getpid()\u548cgetppid()\u53ef\u4ee5\u83b7\u5f97\u8fdb\u7a0b\u7684pid\u548cppid\u3002
"},{"location":"CS/OS/process_syn/#25","title":"2.5 \u8fdb\u7a0b\u7684\u7ec8\u6b62","text":"\u8fdb\u7a0b\u8c03\u7528exit()\u5b9e\u73b0\u7ec8\u6b62\u3002\u4e5f\u662fC\u8bed\u8a00main\u51fd\u6570\u8fd4\u56de\u65f6\u9690\u5f0f\u8c03\u7528\u7684\u4e1c\u897f
\u5f53\u8fdb\u7a0b\u7ec8\u6b62\u65f6\uff0c\u8fdb\u7a0b\u8fdb\u5165terminated\u72b6\u6001\uff0c\u5176\u8d44\u6e90\u88abOS\u56de\u6536\uff0c\u4f46\u662fpid\uff0c\u7ed3\u675f\u72b6\u6001\uff0c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u4ecd\u7136\u4f1a\u88ab\u4fdd\u5b58\uff0c\u56e0\u4e3a\u7236\u8fdb\u7a0b\u6709\u53ef\u80fd\u4f1a\u8c03\u7528wait()\u6765\u83b7\u53d6\u3002
zombie processes: \u5b50\u8fdb\u7a0b\u5df2\u7ec8\u6b62\uff0c\u7236\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u8c03\u7528wait()
orphan processes: \u7236\u8fdb\u7a0b\u7ed3\u675f\u4e86\uff0c\u5b50\u8fdb\u7a0b\u6ca1\u7ed3\u675f\u3002\u6709\u4e9bOS\u4f1a\u628a\u5b50\u8fdb\u7a0b\u7ed3\u675f\u6389\uff0cUNIX\u4f1a\u8ba9init\u79f0\u4e3a\u5176\u7236\u8fdb\u7a0b\u3002
"},{"location":"CS/OS/process_syn/#26-ipcinterprocess-communication","title":"2.6 \u8fdb\u7a0b\u95f4\u901a\u4fe1IPC\uff0cInterProcess Communication","text":"\u662f\u4e3a\u4e86\u5728\u8fdb\u7a0b\u7684\u8d44\u6e90\u76f8\u4e92\u9694\u79bb\uff08\uff1f\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u8ba9\u4e0d\u540c\u7684\u8fdb\u7a0b\u80fd\u76f8\u4e92\u8bbf\u95ee\u8d44\u6e90\uff0c\u534f\u8c03\u5de5\u4f5c\u3002
\u591a\u9053multiprogramming\u73af\u5883\u4e0b\uff0c\u8fdb\u7a0b\u7684\u4e2a\u6570\u901a\u5e38\u5927\u4e8eCPU\u4e2a\u6570\u3002
CPU\u8c03\u5ea6\u662fOS\u5173\u4e8e\u54ea\u4e2aready\u8fdb\u7a0b\u53ef\u4ee5\u8fd0\u884c\u548c\u8fd0\u884c\u591a\u4e45\u7684\u51b3\u5b9a\u3002
\u5177\u4f53\u6765\u8bb2\u4e00\u6b21\u8c03\u5ea6\u5e94\u8be5\u662f\u6307OS\u5c06\u4e00\u4e2a\u8fdb\u7a0b\u4ece5\u79cd\u72b6\u6001\u4e2d\u7684\u4e00\u79cd\u5207\u6362\u5230\u4e86\u53e6\u4e00\u79cd\u7684\u8fc7\u7a0b\u3002
\u76ee\u6807\u662f\u59cb\u7ec8\u5141\u8bb8\u67d0\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u4ee5\u6700\u5927\u5316CPU\u5229\u7528\u7387\uff0c\u540c\u65f6\u4fdd\u8bc1\u4e00\u5b9a\u516c\u5e73\u6027\u3002
\u8c03\u5ea6\u4e0d\u4e00\u5b9a\u662fCPU\u8c03\u5ea6\uff0c\u6709\u53ef\u80fd\u53d1\u751f\u5728\u6240\u6709\u573a\u666f\u3002
\u8c03\u5ea6\u7684\u539f\u56e0\u662f\u80fd\u591f\u4f9b\u7ed9\u7684\u8d44\u6e90\u6570\u91cf\u8fdc\u5c0f\u4e8e\u8bf7\u6c42\u7684\u6570\u91cf\u3002
"},{"location":"CS/OS/process_syn/#31","title":"3.1 \u8c03\u5ea6\u7684\u65f6\u673a","text":"CPU\u8c03\u5ea6\u51fa\u73b0\u5728\u4efb\u610f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u6709\u5982\u4e0b5\u79cd\u8f6c\u6362
\u597d\u770b\u4e00\u70b9\u7684\u770b\u56fe\u5427 \u8c03\u5ea6\u6309\u65f6\u673a\u5206\u7c7b\u5206\u4e24\u79cd
\u8c03\u5ea6\u7684\u8fc7\u7a0b\u5c31\u662f\u4e0a\u4e0b\u6587\u5207\u6362\uff0c\u611f\u89c9\u8fd9\u4e2a\u540d\u5b57\u8bf4\u7684\u662f\u5bf9\u4e8e\u6b63\u5728\u8fd0\u884c\u7684CPU\u91cc\u7684\u8fdb\u7a0b\uff0c\u6240\u8c13\u4e0a\u4e0b\u6587\u5c31\u662fPCB\u5185\u5bb9\u3002
"},{"location":"CS/OS/process_syn/#33","title":"3.3 \u8c03\u5ea6\u7b97\u6cd5\u8bc4\u4ef7","text":"\u8fd9\u4e9b\u76ee\u6807\u53ef\u80fd\u7684\u51b2\u7a81\uff1a - context switch vs. throughput - context switch vs. response time
"},{"location":"CS/OS/process_syn/#34","title":"3.4 \u8c03\u5ea6\u7b97\u6cd5","text":"First-come first-serve (FCFS) | Nonpreemptive
\u5148\u7533\u8bf7CPU\u7684\u8fdb\u7a0b\u5148\u7528\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2aFIFO\u961f\u5217\u5b9e\u73b0\u3002
\u5b83\u4f1a\u5bfc\u81f4convey effort: short process behind long process, \u5c24\u5176\u662f\u5f53\u6709\u7ebf\u7a0b\u8fdb\u5165waiting\u540e\uff0c\u518d\u8fd4\u56de\u7684\u65f6\u5019\u53c8\u8981\u91cd\u65b0\u6392\u961f\u3002
Shortest-job-first (SJF)
SJF\u7684\u6838\u5fc3\u60f3\u6cd5\u662f\u8ba9\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4\u6700\u77ed\u7684\u8fdb\u7a0b\u5148\u6765\u8fd0\u884c \u21d2 \u80fd\u5f97\u5230\u6700\u5c11\u7684\u5e73\u5747\u7b49\u5f85\u65f6\u95f4
\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4 = \uff08\u975e\u62a2\u5360\u5f0f\u8c03\u5ea6\uff09\u8fdb\u7a0b\u603b\u65f6\u95f4\uff08\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u53ef\u80fd\u88ab\u6253\u65ad\uff09=\uff08\u62a2\u5360\u5f0f\u8c03\u5ea6\uff09\u8fdb\u7a0b\u7684\u5269\u4f59\u8fd0\u884c\u65f6\u95f4
\u4f1a\u5206\u5f00\u8ba1\u7b97\u5c31\u884c
SJF\u5728\u4e24\u79cd\u8c03\u5ea6\u65b9\u6cd5\u90fd\u80fd\u83b7\u5f97\u6700\u5c0f\u5e73\u5747\u7b49\u5f85\u65f6\u95f4
\u95ee\u9898\u662f\u6211\u4eec\u4e0d\u77e5\u9053\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4 \u2192 \u6240\u4ee5\u8981\u731c\uff0c\u731c\u7684\u7b97\u6cd5\u662f\u4e4b\u524dCPU\u6267\u884c\u957f\u5ea6\u7684\u6307\u6570\u5e73\u5747
Round-robin (RR) in preemptive
\u505a\u6cd5\uff1a\u5b9a\u4e49\u4e00\u4e2a\u65f6\u95f4\u7247\uff08time slice/time quantum\uff09\uff0c\u5373\u4e00\u4e2a\u56fa\u5b9a\u7684\u8f83\u5c0f\u7684\u65f6\u95f4\u5355\u5143\uff0c\u5982\u679cprocess\u4e0d\u662f\u552f\u4e00\u5728ready queue\u4e2d\u7684\u8fdb\u7a0b\uff0c\u90a3\u5c31\u4e0d\u4f1a\u8fde\u7eed\u8fd0\u884c\u8d85\u8fc7\u4e00\u4e2a\u65f6\u95f4\u7247\u7684\u65f6\u95f4\u3002ready queue\u662fFIFO\u7684\u3002
\u6027\u80fd\uff1a\u6bd4\u8d77SJF\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u66f4\u957f\uff0c\u4f46\u662f\u964d\u4f4e\u4e86response time\u3002\u6027\u80fd\u597d\u574f\u57fa\u672c\u4e0a\u53d6\u51b3\u4e8e\u65f6\u95f4\u7247\u5927\u5c0f\uff0cresponse time\u548coverhead\u51b2\u7a81\u3002\u5982\u679c\u65f6\u95f4\u7247\u2192inf\uff0c\u76f8\u5f53\u4e8eRR\u2192FCFS
\u65f6\u95f4\u7247\u4e00\u822c\u752810~100ms, context-switch\u4e00\u822c\u82b110mius
Priority Scheduling
\u4f18\u5148\u8c03\u5ea6\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u8fdb\u7a0b\uff08\u6839\u636e\u8bfe\u672c\u7684\u4f8b\u5b50\uff0c\u4f18\u5148\u7ea7\u597d\u50cf\u662f\u4e0d\u4f1a\u91cd\u590d\u7684\uff09
\u4f18\u5148\u7ea7\u6807\u51c6\uff1a
\u53ef\u4ee5\u7528priority queue\u5b9e\u73b0
\u53ef\u4ee5\u4e0eRR\u7ed3\u5408\uff0c\u8fd9\u65f6\u5019ready queue\u662f\u7528priority queue\u5b9e\u73b0\u7684
Priority Aging\uff1a\u89e3\u51b3indefinite blocking / starvation\uff0c\u5373\u4f4e\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u6267\u884c\u3002\u53ef\u4ee5\u6839\u636e\u7b49\u5f85\u65f6\u95f4\u9010\u6e10\u589e\u52a0priority\u3002
Multilevel Queue Scheduling
\u53ef\u4ee5\u5c06\u8fdb\u7a0b\u5206\u4e3a\u4e0d\u540c\u7684\u7ec4\uff0c\u6bcf\u4e2a\u7ec4\u5185\u6709\u4e0d\u540c\u8c03\u5ea6\u7b97\u6cd5\u7684ready queue\uff0c\u7ec4\u548c\u7ec4\u4e4b\u95f4\u4e5f\u8981\u8c03\u5ea6\u3002
\u7ec4\u5185\uff1a\u4e00\u822c\u524d\u53f0\u961f\u5217\u4f7f\u7528RR\u4ee5\u4fdd\u8bc1response\uff0c\u540e\u53f0\u53ef\u4ee5FCFS
\u7ec4\u95f4\uff1a\u901a\u5e38\u7ed9\u961f\u5217\u8bbe\u7f6e\u4f18\u5148\u7ea7\uff0c\u7528preemptive priority scheduling\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7ec4\u95f4time-slicing
Multilevel Feedback Queue Scheduling
\u4e0a\u4e00\u4e2a\u7248\u672c\u7684\u52a0\u5f3a\u7248\u3002\u5141\u8bb8\u8fdb\u7a0b\u5728\u7ec4\u95f4\u8fc1\u79fb\u3002
\u8fc7\u7a0b
\u8fd9\u79cd\u7b97\u6cd5\u7684performance\u6839\u636e\u5177\u4f53\u64cd\u4f5c\u7cfb\u7edf\u548c\u5177\u4f53\u5b9e\u73b0\u800c\u5f02\u3002
"},{"location":"CS/OS/process_syn/#4-threads","title":"4. \u7ebf\u7a0b threads","text":""},{"location":"CS/OS/process_syn/#41","title":"4.1 \u52a8\u673a\u548c\u6982\u5ff5","text":"\u5f00\u9500\uff1a
\u56e0\u4e3a\u82e5\u5e72\u8fdb\u7a0b\u53ef\u80fd\u5171\u4eab\u4e00\u4e9b\u5185\u5bb9\uff0c\u5982\u679cOS\u77e5\u9053\u8fd9\u4e9b\u5171\u4eab\uff0c\u5c31\u80fd\u51cf\u5c11\u65b0\u5efa\u8fdb\u7a0b\u7684\u5f00\u9500\u53ca\u8fdb\u7a0b\u5207\u6362\u7684\u65f6\u5ef6\u3002
\u21d2 \u5f15\u5165\u7ebf\u7a0bthreads\uff0c\u7ebf\u7a0b\u5c5e\u4e8e\u8fdb\u7a0b
\u5b83\u4e5f\u6709thread id (tid), PC, register set \u548c runtime stack\u3002
\u7ebf\u7a0b\u4e0e\u540c\u4e00\u8fdb\u7a0b\u7684\u5176\u5b83\u7ebf\u7a0b\u5171\u4eabcode section, data section, heap, open files, signals
Linux\u4e2d\u7ebf\u7a0b\u4e5f\u53eb\u8f7b\u91cf\u7ea7\u8fdb\u7a0bLight Weight Process\u3002
\u5982\u679cOS\u652f\u6301\u7ebf\u7a0b\uff0c\u90a3\u8c03\u5ea6\u7684\u5c31\u662f\u5185\u6838\u7ea7\u7ebf\u7a0b\u800c\u4e0d\u662f\u8fdb\u7a0b\uff0c\u4e5f\u5c31\u662f\u8bf4\u7ebf\u7a0b\u662f\u8fd0\u884c\u4ee5\u53caCPU\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u5143\u3002
\u533a\u5206\uff1a\u8fdb\u7a0b\u662f\u5206\u914d\u8d44\u6e90\u7684\u57fa\u672c\u5355\u5143
"},{"location":"CS/OS/process_syn/#42","title":"4.2 \u4f18\u7f3a\u70b9","text":"\u591a\u7ebf\u7a0b\u7f16\u7a0bMulti-Threaded Programming\u7684\u4f18\u70b9\u6709\uff1a
\u7f3a\u70b9
- \u7528\u6237\u7ea7\u7ebf\u7a0buser-level thread\uff1a\u5728OS\u4e0a\u53ea\u662f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u5305\u542b\u7ebf\u7a0b\u5e93thread library\uff0c\u8d1f\u8d23\u7ebf\u7a0b\u7684\u521b\u5efa\u548c\u5207\u6362\uff1b\u5185\u6838\u7ea7\u7ebf\u7a0b\u7531OS\u652f\u6301\u8fd9\u4e9b\u64cd\u4f5c - \u7528\u6237\u901a\u8fc7OS\u63d0\u4f9b\u7684\u7ebf\u7a0b\u5e93\u51fd\u6570\u521b\u5efa\uff0c - \u4f18\u70b9\uff1a1\uff09\u4e0d\u5360\u7528OS\u7684tid\uff0c\u7406\u8bba\u4e0a\u53ef\u4ee5\u652f\u6301\u6bd4\u5185\u6838\u7ea7\u7ebf\u7a0b\u66f4\u591a\u7684\u7ebf\u7a0b\u6570 2\uff09\u8c03\u5ea6\u7b49\u64cd\u4f5c\u5728\u7528\u6237\u6001\uff0c\u4e0d\u9700\u8981\u8fdb\u5165\u5185\u6838\u6001 3\uff09\u5bb9\u6613\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u8c03\u5ea6\u7b97\u6cd5 - \u7f3a\u70b9\uff1a1\uff09\u4e00\u65e6\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u963b\u585e\uff0c\u90a3\u4e48OS\u770b\u6765\u5c31\u662f\u6574\u4e2a\u8fdb\u7a0b\u88ab\u963b\u585e\u4e86\uff0c\u5c31\u4f1a\u8ba4\u4e3a\u8be5\u8fdb\u7a0b\u7684\u5176\u5b83\u7ebf\u7a0b\u4e5f\u963b\u585e\u4e86\u3002\u5982\u679c\u662f\u5185\u6838\u7ea7\u7ebf\u7a0b\u5c31\u53ea\u963b\u585e\u8fd9\u4e2a\u7ebf\u7a0b 2\uff09\u540c\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\u7684\u591a\u4e2a\u7528\u6237\u7ea7\u7ebf\u7a0b\u65e0\u6cd5\u5728\u591a\u6838\u4e0a\u5206\u522b\u8fd0\u884c - \u5185\u6838\u7ea7\u7ebf\u7a0bkernel-level thread\uff1a
\u591a\u7ebf\u7a0b\u6a21\u578b\uff1a\u6709\u7684OS\u540c\u65f6\u652f\u6301\u7528\u6237\u7ea7\u548c\u5185\u6838\u7ea7\uff0c\u6709\u51e0\u79cd\u7528\u6237\u7ea7\u548c\u5185\u6838\u7ea7\u7684\u6620\u5c04\u65b9\u6cd5
\uff081\uff09\u7b49\u4e8e\u53ea\u652f\u6301\u7528\u6237\u7ea7 \uff082\uff09\u7b49\u4e8e\u53ea\u652f\u6301\u5185\u6838\u7ea7 \uff083\uff09m\u4e2a\u7528\u6237\u7ea7\u53ef\u4ee5\u6620\u5c04\u5230n\u4e2a\u5185\u6838\u7ea7 Linux\u7ebf\u7a0b\uff1a\u6ca1\u6709\u7279\u522b\u533a\u5206\u8fdb\u7a0b\u548c\u7ebf\u7a0b\uff0c\u90fd\u662f\u53ebtask
\u4e0d\u77e5\u9053\u8fd9\u91cc\u8003\u4e0d\u8003\u8981\u662f\u8003\u4e86\u56de\u53bbrefer\u4e00\u4e0b
5 \u7ebf\u7a0b - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io)
"},{"location":"CS/OS/process_syn/#5-synchronization","title":"5. \u540c\u6b65\u548c\u540c\u6b65\u5de5\u5177 Synchronization","text":"Synchronization\u5c31\u662f\u89c4\u5b9a\u8fdb\u7a0b\u6240\u505a\u7684\u5de5\u4f5c\u4e4b\u95f4\u7684\u987a\u5e8f\u6216\u8005\u5148\u5e8f\u5173\u7cfb\uff0c\u4ece\u800c\u9632\u6b62\u4e00\u4e9b\u975e\u6cd5\u60c5\u51b5\u53d1\u751f\u7684\u65b9\u6cd5\u3002
"},{"location":"CS/OS/process_syn/#51-cs-problem","title":"5.1 \u5f15\u5165\u548cCS Problem","text":"Cooperation process\u662f\u53ef\u4ee5\u5f71\u54cd\u7cfb\u7edf\u4e2d\u5176\u5b83\u8fd0\u884c\u8fdb\u7a0b\u6216\u88ab\u5176\u5b83\u8fdb\u7a0b\u5f71\u54cd\u7684\u8fdb\u7a0b\u3002
Cooperating System\u4f1a
e.g. Bounded-buffer problem
\u7ed9\u5b9a\u4e24\u4e2a\u8fdb\u7a0bproducer\u548cconsumer\uff0c\u5171\u7528\u5927\u5c0f\u4e3an\u7684buffer\u3002
producer\u751f\u4ea7\u6570\u636e\u653e\u5165buffer\uff0cconsumer\u4ecebuffer\u4e2d\u4f7f\u7528\u6570\u636e
\u9650\u5b9a\u6761\u4ef6\uff1aproducer\u4e0d\u5e94\u5728buffer\u6ee1\u65f6\u653e\u5165\u6570\u636e\uff0cconsumer\u4e5f\u4e0d\u5e94\u5f53\u5728buffer\u7a7a\u65f6\u53d6\u51fa\u6570\u636e
\u60f3\u8c61\u4e2d\u7684\u4e24\u4e2a\u8fdb\u7a0b
/* producer process */\nwhile (true){\n/* produce an item in nert_produced */\nwhile (count == BUFFER_SIZE)\n; /* do nothing */\nbuffer[in] = next_produced;\nin = (in+1) % BUFFER_SIZE;\ncount++;\n}\n/* Consumer Process */\nwhile (true){\nwhile (count == 0)\n; /* do nothing */\nnext_consumed = buffer[out];\nout = (out + 1) % BUFFER_SIZE;\ncount --;\n/* consume the item in next_consumed */\n}\n
\u5982\u679ccount\u7684\u503c\u662f\u9519\u8bef\u7684\uff1f \u4f8b\u5b50\u7684\u610f\u601d\u662f\uff0c++\u548c\u2014\u90fd\u662f\u7cfb\u7edf\u5b9e\u73b0\u7684\uff0c\u5982\u679c\u5171\u7528count\u8bfb\u53d6\u7684\u65f6\u95f4\u6070\u597d\u649e\u4e0a\uff0ccount\u7684\u503c\u5c31\u4e0d\u5bf9
\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u7684\u539f\u56e0\u662f\u6211\u4eec\u5141\u8bb8\u4e24\u4e2a\u8fdb\u7a0b\u540c\u65f6\u64cd\u7eb5\u53d8\u91cfcount\u3002
e.g. kernel\u4e2d\uff1a\u4e24\u4e2a\u8fdb\u7a0b P0\u00a0\u548c P1\u00a0\u540c\u65f6\u00a0fork()
\u00a0\u65f6\uff0c\u5982\u679c\u4e0d\u52a0\u9650\u5236\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u524d\u4f8b\u7684\u60c5\u51b5\uff0c\u5373\u5728\u67d0\u4e00\u4e2a\u8fdb\u7a0b\u628a\u5f53\u524d\u7684\u00a0next_avaliable_pid
\u00a0\u5206\u914d\u7ed9\u4ed6\u7684 child \u540e\uff0c\u5728\u6ca1\u6765\u5f97\u53ca\u66f4\u65b0\u00a0next_avaliable_pid
\u00a0\u524d\uff0c\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u4e86\u00a0next_avaliable_pid
\u00a0\u6765\u7ed9 child \u5206\u914d PID\uff0c\u8fd9\u5c31\u4f1a\u5bfc\u81f4\u4e24\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\u4f7f\u7528\u540c\u4e00\u4e2a PID \u7684\u60c5\u51b5\u3002
Race Condition\uff1a\u591a\u4e2a\u8fdb\u7a0b\u540c\u65f6\u64cd\u63a7\u4e00\u4e2a\u6570\u636e\uff0c\u7531\u64cd\u63a7\u51fa\u73b0\u7684\u987a\u5e8f\u51b3\u5b9a\u7ed3\u679c
\u5fc5\u987b\u4fdd\u8bc1\u540c\u4e00\u4e2a\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u64cd\u63a7\u67d0\u4e2a\u53d8\u91cf\u3002
The Critical-Section Problem \uff08CS Problem\uff09
\u8003\u8651\u4e00\u4e2a\u6709n\u4e2a\u8fdb\u7a0b\u7684\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u4e2d\u90fd\u6709\u4e00\u6bb5\u4ee3\u7801\u53ef\u80fd\u4fee\u6539\u5176\u4ed6\u81f3\u5c11\u4e00\u4e2a\u8fdb\u7a0b\u516c\u7528\u7684\u6570\u636e\uff0c\u79f0\u4e3acritical section\u3002\u8fd9\u4e2a\u7cfb\u7edf\u9700\u8981\u6ee1\u8db3\u7684\u91cd\u8981\u6027\u8d28\u662f\uff0c\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u6b63\u5728\u8fd0\u884ccritical section\u65f6\uff0c\u5176\u5b83\u8fdb\u7a0b\u90fd\u4e0d\u80fd\u8fdb\u5165critical section
\u5c06\u8fd9\u4e2a\u95ee\u9898\u79f0\u4e3acritical section problem\uff0c\u4e5f\u5c31\u662f\u8981\u8bbe\u8ba1\u4e00\u79cd\u8fbe\u6210\u4e00\u81f4\u884c\u7684\u65b9\u6cd5\u3002\u6216\u8005\u8bf4\u8bbe\u8ba1\u4e00\u79cd\u8ba9\u5404\u79cd\u8fdb\u7a0b\u540c\u6b65\u4ece\u800c\u5b89\u5168\u5171\u4eab\u6570\u636e\u7684\u534f\u8bae\u3002
\u8fd9\u6bb5\u7a0b\u5e8f\u7684\u793a\u610f\u56fe\u5982\u4e0b\uff1a \u6bcf\u4e2a\u8fdb\u7a0b\u5fc5\u987b\u5728entry section\u4e2d\u7533\u8bf7\u8fdb\u5165critical section\u7684\u8bb8\u53ef\uff1b\u5728critical section\u8fd0\u884c\u7ed3\u675f\u540e\u8fdb\u5165exit section\uff0c\u5728\u8fd9\u91cc\u8bb8\u53ef\u88ab\u91ca\u653e\u3002
\u2757\u2757\u2757
Critical section problem\u7684\u89e3\u51b3\u65b9\u6cd5\u5fc5\u987b\u6ee1\u8db3\u5982\u4e0b\u4e09\u4e2a\u8981\u6c42
\u63a5\u4e0b\u6765\u6211\u4eec\u4ecb\u7ecd\u7684\u7b97\u6cd5\u90fd\u662f\u5728\u4e00\u6b65\u4e00\u6b65\u6ee1\u8db3\u8fd9\u4e09\u4e2a\u8981\u6c42
Kernel\u4e2d\u7684CS Problem
\u9700\u8981\u4fdd\u8bc1kernel\u7684\u8bbe\u8ba1\u5b9e\u73b0\u4e86critical section
kernel\u7684\u5b9e\u73b0\u5206\u4e24\u79cd\u7c7b\u578b\uff1a
\u533a\u522b\u662f\u662f\u5426\u5141\u8bb8kernel mode\u88ab\u62a2\u5360
\u62a2\u5360\u5f0f\u5185\u6838\u66f4\u96be\u8bbe\u8ba1\uff0c\u4f46\u540c\u65f6\u4e5f\u54cd\u5e94\u66f4\u5feb\u3002
"},{"location":"CS/OS/process_syn/#52-petersons-solution","title":"5.2 Peterson\u2019s Solution","text":"\u7701\u6d41\uff1a\u8ba9\u4e24\u4e2a\u8fdb\u7a0b\u5171\u4eab\u4e00\u4e2a\u53d8\u91cf\uff0c\u65e2\u6709turn\uff08\u8f6e\u5230\u8c01\u80fd\u8fdb\u53bb\uff09\u4e5f\u6709flag\uff08\u8fdb\u7a0b\u662f\u5426ready\uff09\u3002\u5f53flag[\u67d0\u4e2a\u8fdb\u7a0b]\u4e14turn=\u8be5\u8fdb\u7a0b\uff0c\u5c31\u53ef\u4ee5\u8fdb\u53bb\u3002
\ud83d\udca1 \u60f3\u8981\u7406\u89e3PS\u7b97\u6cd5\uff0c\u8bf7\u60f3\u8c61\u4e24\u4e2a\u4eba\u4e92\u76f8\u8ba9\u5ea7\uff0cA\u5148\u8bf4\u4f60\u5750\u5427\uff0cB\u518d\u8bf4\u4f60\u5750\u5427\uff0c\u8fd9\u65f6A\u5750\u4e0b\u3002 A\u83b7\u5f97\u6905\u5b50\u6709\u4e24\u4e2a\u5145\u8981\u6761\u4ef6\uff1a A\u60f3\u5750: flag[A] = 1 \u5728B\u8ba9\u5ea7\u4e4b\u524d\uff0cA\u5df2\u7ecf\u8ba9\u8fc7\u5ea7\u4e86: turn \u2260 A \u8bf4\u660e\u4e4b\u524dturn\u66fe\u7ecf\u88ab\u8d4b\u4e3aA\uff0c\u73b0\u5728\u662fBint turn; // who is allowed to enter\nboolean flag[2]; // ready to enter its CS\nvoid foo(){\nwhile (true){\nflag[i] = true; // mark self ready\nturn = 1-i; // assert that if the other process wishes to enter its CS, it can do so;\nwhile (flag[1-i] && turn = 1-i); // wait\n/* critical section */\nflag[i] = false; // set ready to false\n/* reminder section */\n}\n}\n
\u5176\u4e2d i
\u662f0\u62161\uff0c\u8868\u793a\u7b2ci\u4e2a\u8fdb\u7a0b\u3002 turn
\u662f\u5f53\u524d\u6709\u6743\u8fdb\u5165critical section\u7684\u8fdb\u7a0b\uff080\u62161\uff09; flag
\u662f\u7b2ci\u4e2a\u8fdb\u7a0b\u662f\u5426\u51c6\u5907\u597d\u8fdb\u5165critical section\uff0c\u521d\u59cb\u503c\u5747\u4e3aFALSE\u3002
To enter the critical section, process Pi first sets flag[i]
to be true and then sets turn
to the value 1-i
(the other process), thereby asserting that is the other process wishes to enter the critical section, it can do so. If both processes try to enter at the same time, turn
will be set to both 0
and 1
at roughly the same time. Only one of these assignments will last; the other will occur but will be overwritten immediately. The eventual value of turn
determines which of the two processes is allowed to enter its critical section first.
Peterson\u2019s Solution\u6ee1\u8db3\u540c\u6b65\u7b97\u6cd5\u5fc5\u987b\u6ee1\u8db3\u7684\u4e09\u4e2a\u6027\u8d28\uff1a
Bakery Algorithm\uff1a
2\u4e2a\u8fdb\u7a0b\u7248\u672c\u7684PS\u3002\u9700\u8981\u904d\u5386\u6240\u6709\u8fdb\u7a0b\u67e5\u770b\u5927\u5bb6\u7684turn
Reordering \u91cd\u6392\u5e8f
PS\u7684\u7f3a\u70b9\u662f\u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u4e0a\u4e0d\u4e00\u5b9a\u9002\u7528\u3002\u56e0\u4e3a\u73b0\u4ee3\u7684\u5904\u7406\u5668\u548c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\u800c\u5bf9\u4e00\u4e9b\u8bfb\u5199\u64cd\u4f5c\u8fdb\u884c\u91cd\u6392\u3002
\u91cd\u6392\u7684\u65f6\u5019\u4f1a\u8003\u8651\u91cd\u6392\u5728\u5355\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\u7684\u5408\u7406\u6027\uff08\u8ba1\u7b97\u7ed3\u679c\u662f\u7a33\u5b9a\u4e14\u6b63\u786e\u7684\uff09\u3002\u4f46\u662f\u8fd9\u6837\u4e0d\u80fd\u4fdd\u8bc1\u5728\u591a\u7ebf\u7a0b\u5171\u7528\u6570\u636e\u65f6\u7684\u6b63\u786e\u6027\uff0c\u53ef\u80fd\u5728\u591a\u7ebf\u7a0b\u5171\u7528\u65f6\u51fa\u73b0\u4e0d\u786e\u5b9a\u6216\u4e0d\u5bf9\u7684\u8f93\u51fa\u3002
e.g. \u7f16\u8bd1\u5668\u548c\u5904\u7406\u5668\u53ef\u80fd\u4f1a\u5bf9\u6570\u636e\u8bfb\u53d6\u987a\u5e8f\u8fdb\u884creorder\uff0c\u4ee5\u4f7f\u4e0d\u9700\u8981\u4ea4\u66ff\u8bfb\u53d6\u4e24\u4e2a\u6570\u636e\u7684\u503c\uff0c\u800c\u662f\u76f8\u540c\u8bfb\u53d6\u653e\u5728\u4e00\u8d77\u3002
\u4e3a\u4e86\u89e3\u51b3\u91cd\u6392\u5e8f\u5bfc\u81f4\u7684\u5728\u591a\u7ebf\u7a0b\u4e0b\u4e0d\u7a33\u5b9a\uff0c\u6211\u4eec\u5f15\u5165\uff1a
Memory Barrier
\u5b83\u7528\u6765\u4fdd\u8bc1\u5176\u4e4b\u524d\u7684\u5185\u5b58\u8bbf\u95ee\u5148\u4e8e\u4e4b\u540e\u7684\u5b8c\u6210\u3002\u5373\uff0c\u5728\u67d0\u4e2a\u64cd\u4f5c\u524d\uff0c\u5185\u5b58\u7684\u6539\u53d8\u5bf9\u5176\u5b83\u5904\u7406\u5668\u4e0a\u7684\u8fdb\u7a0b\u90fd\u662f\u53ef\u89c1\u7684\u3002
\u52a0memory barrier\u7684\u4e00\u79cd\u65b9\u6cd5
while (!flag)\nmemory_barrier();\nprint x;\n
\u8fd9\u6837\u5c31\u4fdd\u8bc1\u4e86flag\u5728x\u4e4b\u524d\u88ab\u52a0\u8f7d\u4e86\u3002
Memory Model
\u53e6\u5916\uff0c\u5728\u73b0\u4ee3\u7684\u4f53\u7cfb\u7ed3\u6784\u4e0a\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u5199\u4e86\u5bf9\u5e94\u7684\u53d8\u91cf\u540e\u53ef\u80fd\u4e0d\u4f1a\u7acb\u5373\u5199\u56de\u5185\u5b58\uff0c\u8fd9\u4e5f\u6709\u53ef\u80fd\u5bfc\u81f4\u95ee\u9898\u3002
\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u51b3\u5b9a\u54ea\u5757\u5185\u5b58\u7ed9\u54ea\u4e2a\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u53eb\u505amemory model\u3002memory model\u6709\u4e24\u79cd\u7c7b\u578b
\u6709\u4e24\u4e2a\u786c\u4ef6\u6307\u4ee4\u80fd\u5e2e\u52a9\u5b9e\u73b0\u4e92\u65a5\u548c\u540c\u6b65
\u8bb8\u591a\u73b0\u4ee3\u7cfb\u7edf\u63d0\u4f9b\u786c\u4ef6\u6307\u4ee4\u6765\u4fee\u6539word\u7684\u5185\u5bb9\uff0c\u6216\u8005\u7528\u4e8eatomically (uniterruptably\uff0c\u4e0d\u53ef\u88ab\u6253\u65ad\u5730)\u4ea4\u6362\u4e24\u4e2aword\u3002
\u7528\u6237\u4e00\u822c\u4e0d\u7528\u5173\u5fc3\u7279\u5b9a\u673a\u5668\u6307\u4ee4\uff0c\u53ef\u4ee5\u7528\u6307\u4ee4 test_and_set()
\u548c compare_and_swap()
\u62bd\u8c61\u4e86\u89e3\u8fd9\u4e9b\u673a\u5668\u6307\u4ee4\u80cc\u540e\u7684\u542b\u4e49\u3002
test_and_set
\u7684\u5b9a\u4e49\u662f\u628a\u4e00\u4e2atrue\u8f93\u5165\u5230\u786c\u4ef6\uff0c\u5e76\u4e14\u628a\u53d8\u91cf\u539f\u6765\u7684\u503c\u8fd4\u56de\u3002\u5b83\u662f\u4e00\u4e2a\u57fa\u672c\u6307\u4ee4\u5668\u4ef6\u3002
bool test_and_set(bool *target) {\nbool rv = *target;\n*target = true;\nreturn rv;\n}\n
\u5b83\u7684\u91cd\u8981\u7279\u5f81\u662f\uff0c\u5b83\u7684\u6267\u884c\u662fatomic\u7684\u3002
\u8fd9\u4e2a\u6307\u4ee4\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0mutual exclusive: \u5b9a\u4e49\u4e00\u4e2abool\u53d8\u91cf lock
\uff0c\u521d\u59cb\u5316\u4e3afalse\u3002
\u4e3a\u4ec0\u4e48\u53ef\u4ee5\uff1a\u5982\u679c\u00a0lock
\u00a0\u5728 Entry Section \u65f6\u4e3a true\uff0c\u90a3\u4e48\u00a0test_and_set(&lock)
\u00a0\u5c06\u8fd4\u56de true\uff0c\u56e0\u6b64\u4f1a\u59cb\u7ec8\u5728 while \u5faa\u73af\u4e2d\u8be2\u95ee\u3002\u76f4\u5230\u67d0\u4e2a\u65f6\u523b\u00a0lock
\u00a0\u4e3a false\uff0c\u90a3\u4e48\u00a0test_and_set(&lock)
\u00a0\u5c06\u8fd4\u56de false \u540c\u65f6\u5c06\u00a0lock
\u00a0\u7f6e\u4e3a true\uff0c\u8fdb\u7a0b\u8fdb\u5165 Critical Section\uff0c\u540c\u65f6\u4fdd\u8bc1\u5176\u4ed6\u8fdb\u7a0b\u65e0\u6cd5\u8fdb\u5165 Critical Section\u3002\u5f53\u6301\u9501\u7684\u8fdb\u7a0b\u5b8c\u6210 Critical Section \u7684\u8fd0\u884c\uff0c\u5b83\u5728 Exit Section \u4e2d\u91ca\u653e\u00a0lock
\u00a0\uff0c\u4ece\u800c\u5141\u8bb8\u5176\u4ed6\u8fdb\u7a0b\u8fdb\u5165 Critical Section\u3002\u800c\u5982\u679c\u67d0\u4e2a\u65f6\u523b\u00a0lock
\u00a0\u4e3a false\uff0c\u800c\u6709\u4e24\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u51e0\u4e4e\u540c\u65f6\u8c03\u7528\u4e86\u00a0test_and_set(&lock)
\u00a0\u3002\u4f46\u7531\u4e8e\u5b83\u662f atomic\uff08none-or-all\uff09\u7684\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u8fd4\u56de false\u3002
\u4e0d\u80fd\u5b9e\u73b0bounded waiting\u600e\u4e48\u529e\uff0c\u6709\u7684\u8fdb\u7a0b\u53ef\u80fd\u5c31\u4e00\u76f4\u6ca1\u6709\u62ff\u5230\u9501\uff1a\u52a0\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u627e\u4e0b\u4e00\u4e2a\u53ef\u4ee5\u8fdb\u5165\u7684\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u6700\u591a\u7b49\u5168\u90e8\u904d\u5386\u5b8c\u4e00\u904d\u5c31\u8f6e\u5230\u81ea\u5df1
while (true){\n/* Entry Section */\nwhile (test_and_set(&lock))\n; /* do something */\n/* Critical Section */\n/* Exit Section */\nj = (i + 1) % n;\nwhile ((j != i) && !waiting[j]))\nj = (j + 1) % n;\nif (j == i)\nlock = false;\nelse\nwaiting[j] = false;\n/* Remainder Section */\n}\n
compare_and_swap()
\u7528\u8f6f\u4ef6\u6765\u5b9e\u73b0\u6027\u80fd\u975e\u5e38\u5dee\uff0c\u7528\u8f6f\u4ef6\u6765\u5b9e\u73b0\u4f1a\u53d8\u597d\u3002\u5b83\u7684\u5b9a\u4e49\u662f
int compare_and_swap(int *value, int expected, int new_value){\nint temp = *value;\nif (*value == expected)\n*value = new_value;\nreturn temp;\n}\n
\u53ef\u89c1\u5176\u5b9ecompare_and_swap()
\u4e0etest_and_set()
\u4f5c\u7528\u7c7b\u4f3c\u3002
\u7528compare_and_swap()
\u5b9e\u73b0mutual exclusive
while (true) {\n/* Entry Section */\nwhile (compare_and_swap(&lock, 0, 1) != 0)\n; /* do nothing */\n/* Critical Section */\n/* Exit Section */\nlock = 0;\n/* Remainder Section */\n}\n
"},{"location":"CS/OS/process_syn/#54-semaphores","title":"5.4 \u4fe1\u53f7\u91cf Semaphores","text":"\u662f\u4e00\u4e2a\u6574\u578b\u53d8\u91cf\uff0c\u9664\u4e86\u521d\u59cb\u5316\u5916\uff0c\u53ea\u80fd\u901a\u8fc7\u4e24\u4e2aatomic\u64cd\u4f5c wait()
\u548c signal()
\u6765\u8bbf\u95ee\u3002
void wait(S){\nwhile (S <= 0)\n; /* busy waiting */\nS--;\n}\nvoid signal(S){\nS++;\n}\n
\u6709\u4e24\u79cdsemaphore\uff1a
e.g. Consider P1 and P2 that require S1 to happen before S2, create a semaphore \u201csynch\u201d initialized to 0.
P1:\nS1;\nsignal(synch);\nP2:\nwait(synch);\nS2;\n
\u5982\u679c\u60f3\u8981\u89e3\u51b3semaphore\u7684busy waiting\u95ee\u9898\uff0c\u53ef\u4ee5\u5f15\u5165waiting queue
typedef struct {\nint value;\nstruct list_head * waiting_queue;\n} semaphore;\nwait(semaphore *S) {\nS->value--;\nif (S->value < 0) {\nadd this process to S->list;\nblock();\n}\n}\nsignal(semaphore *S) {\nS->value++;\nif (S->value <= 0) {\nremove a process P from S->list;\nwakeup(P);\n}\n}\n
\u53ef\u80fd\u4f1a\u5bfc\u81f4deadlock
"},{"location":"CS/OS/process_syn/#55-atomic-variable","title":"5.5 Atomic Variable","text":"\u90a3\u5c31\u76f4\u63a5\u7528compare_and_swap()
\u6765\u505a\u6210\u4e00\u4e9batomic\u7684\u673a\u5668\u6307\u4ee4\u5de5\u5177
e.g. count++ \u662f\u53ef\u4ee5\u6253\u65ad\u7684\uff0c\u4f46\u662f\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u4e0d\u53ef\u6253\u65ad\u7684increment(&count)
void increment(atomic_int *v){\nint temp;\ndo {\ntemp = *v;\n} while (temp != compare_and_swap(v, temp, temp+1)); // \u5b83\u4e0d\u4f1a\u88ab\u6253\u65ad\n}\n
\u8981\u8bb0\u5f97\u5b83\u53ea\u80fd\u89e3\u51b3\u53d8\u91cf\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u7684race condition\u3002\u6b64\u65f6\u53ea\u6709\u5f85\u66f4\u65b0\u53d8\u91cf\u4e00\u4e2a\u53d8\u91cf\u5728\u7b49\u5f85\u8bfb\u53d6\u3002\u5982\u679c\u6709\u4e24\u4e2aconsumer\u7b49\u5f85\u8bfb\u53d6\uff0c\u4f46count\u6539\u53d8\u65f6\u53ea\u4f1a\u4ea7\u751f\u4e00\u4e2a\u503c\u5728buffer\u91cc\uff0c\u90a3\u5c31\u4e0d\u884c\u3002
"},{"location":"CS/OS/process_syn/#56-mutex-mutual-exclusion-lock","title":"5.6 Mutex (Mutual Exclusion Lock)","text":"\u7528\u8f6f\u4ef6\u65b9\u6cd5\u89e3\u51b3CS\u3002
\u8ba9\u8fdb\u7a0b\u5148\u5728entry section\u7533\u8bf7acquire()\u4e00\u4e2a\u9501\uff0c\u7136\u540e\u5728exit section release()\u4e00\u4e2a\u9501\u3002\u7136\u540e\u7528\u4e00\u4e2abool\u53d8\u91cf\u6765\u770b\u5b83\u662f\u5426available
while (true){\nacquire();\n/* critical section */\nrelease();\n/* remainder section */\n}\nvoid acquire(){\nwhile (!available)\n; /* busy waiting */\navailable = false;\n}\nvoid release(){\navailble = true;\n}\n
\u56e0\u4e3a\u8fd8\u9700\u8981\u4fdd\u8bc1\u4e92\u65a5\uff0c\u9700\u8981\u4fdd\u8bc1acquire\u662f\u539f\u5b50\u6027\u7684\uff0c\u90a3\u5c31\u7528\u4e0a\u8ff0\u4e24\u4e2a\u786c\u4ef6\u5de5\u5177\u6765\u5b9e\u73b0\u3002\u4ee3\u7801\u540c\u5bf9\u5e94\u8282\uff0c\u4e0d\u8d58\u8ff0\u3002
\u7f3a\u70b9\uff1a\u9700\u8981busy waiting\uff0c\u5f53\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5728CS\u4e2d\u65f6\uff0c\u5176\u5b83\u8fdb\u7a0b\u9700\u8981\u5728acquire()\u4e2dspin\uff0c\u6240\u4ee5\u4e5f\u79f0\u4e3aspinlock\u3002\u5982\u679c\u6709N\u4e2a\u8fdb\u7a0b\u540c\u65f6\u4f7f\u7528\u4e00\u4e2aCPU\uff0c\u90a3\u4e48\u5c06\u5927\u7ea6\u6709(N-1)/N\u7684\u6d6a\u8d39\u3002\u5982\u679c\u6709\u8fdb\u7a0b\u5728\u4f01\u56feacquire\u4e00\u4e2a\u9501\u65f6\u88ab\u7ec4\u7ec7\uff0c\u79f0\u5b83\u4e3acontended\uff08\u88ab\u4e89\u593a\uff09\uff1b\u53cd\u4e4b\u79f0\u4e3auncontended\u3002
\u8fd8\u53ef\u4ee5\u8003\u8651\u4e0b\u9762\u7684\u8bbe\u8ba1\uff0c\u5176\u4e2dyield()\u4f1a\u4f7f\u7a0b\u5e8f\u4ecerunning\u8f6c\u4e3aready\uff0c\u4ece\u800c\u8ba9\u51faCPU
void acquire() {\nwhile (compare_and_swap(&avaliable, 1, 0) != 1)\nyield();\n}\nvoid release() {\navaliable = true;\n}\n
\uff08\u8fd9\u4e2a\u5730\u65b9\u771f\u7684\u771f\u7684\u6ca1\u770b\u61c2\uff09
"},{"location":"CS/OS/process_syn/#57-priority-inversion","title":"5.7 Priority Inversion","text":"e.g.
Three processes PL, PM and PN with priority PL < PM < PH.
PL holds a lock that was requested by PH \u2192 PH is blocked.
PM becomes ready and preempted the PL
It effectively inverts the relative priorities of PM and PH.
\u5177\u6709\u4e2d\u7b49\u4f18\u5148\u7ea7\u7684PM\u5f71\u54cd\u4e86\u9ad8\u4f18\u5148\u7ea7\u7684PH\u7684\u7b49\u5f85\u65f6\u95f4\uff0c\u8fd9\u6837\u662f\u4e0d\u5bf9\u7684\u3002
\u89e3\u51b3\u65b9\u6848\uff1a
\u53ef\u4ee5\u901a\u8fc7\u4f18\u5148\u7ea7\u7ee7\u627fpriority inheritance\u6765\u89e3\u51b3\u3002\u6240\u6709\u6b63\u5728\u8bbf\u95ee\u8d44\u6e90\u7684\u8fdb\u7a0b\uff08\u5982PL\uff09\u9700\u8981\u83b7\u5f97\u8bbf\u95ee\u8fd9\u4e2a\u8d44\u6e90\u7684\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff08PH\uff09\uff0c\u76f4\u5230\u5176\u7528\u5b8c\u6709\u5173\u8d44\u6e90\u4e3a\u6b62\u3002\u6bd4\u5982\u4e0a\u4f8b\u4e2d\uff0cPL\u4f1a\u4e34\u65f6\u7ee7\u627fPL\u7684\u4f18\u5148\u7ea7\uff0c\u7136\u540ePH\u8fd0\u884c\uff0c\u6700\u540ePM\u8fd0\u884c\u3002
"},{"location":"CS/OS/process_syn/#6","title":"6. \u7ecf\u5178\u540c\u6b65\u95ee\u9898","text":"\u4e00\u822c\u6211\u4eec\u7528\u4fe1\u53f7\u91cf\u89e3\u51b3\u95ee\u9898
\u4fe1\u53f7\u91cf\u7684\u903b\u8f91\uff1a\u4e00\u4e2a\u4fe1\u53f7\u91cf\u7528\u6765\u8868\u793a\u4e00\u7c7b\u201c\u8d44\u6e90\u201d\u7684\u4f59\u91cf\u3002wait()\u7b49\u5f85\u5230\u5176\u6709\u4f59\u91cf\u65f6\u4ece\u4e2d\u53d6\u8d70\u4e00\u4e2a\uff0c\u800csignal()\u91ca\u653e\u4e00\u4e2a\u8d44\u6e90\u3002
\uff08\u4e0a\u8fb9\u8fd9\u6bb5\u5728\u5199\u4ec0\u4e48\uff09
"},{"location":"CS/OS/process_syn/#61-bounded-buffer-problem","title":"6.1 Bounded-buffer Problem","text":"\ud83d\udca1 \u7ed9\u5b9a\u4e24\u4e2a\u8fdb\u7a0b\uff1aproducer\u548cconsumer\uff0c\u5171\u7528\u5927\u5c0f\u4e3an\u7684buffer\u3002producer\u751f\u4ea7\u6570\u636e\u653e\u5165buffer\uff0cconsumer\u4ecebuffer\u4e2d\u53d6\u51fa\u6570\u636e\u5e76\u4f7f\u7528\u4e4b\u3002 \u8be5\u95ee\u9898\u9700\u8981\u4fdd\u8bc1\uff1aproducer\u4e0d\u5e94\u5f53\u5728buffer\u6ee1\u65f6\u653e\u5165\u6570\u636e\uff0cconsumer\u4e5f\u4e0d\u5e94\u5f53\u5728buffer\u7a7a\u65f6\u53d6\u51fa\u6570\u636e\u3002\u9996\u5148\uff0c\u6839\u636e\u6211\u4eec\u5728\u524d\u4e00\u8282\u4e2d\u7684\u8ba8\u8bba\uff0cproduce\u548cconsume\u7684\u8fc7\u7a0b\u4f1a\u8bbf\u95ee\u5230buffer\u7684\u8d44\u6e90\uff0c\u56e0\u6b64\u8bbf\u95eebuffer\u662fcritical section\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u9501\uff08\u6216\u8005\u4fe1\u53f7\u91cf\uff09\u6765\u63a7\u5236\u5bf9buffer\u7684\u8bbf\u95ee\u3002
\u8ba8\u8bba\u4e86\u4e00\u4e0b\u9501\u6c38\u8fdc\u4e0d\u53ef\u80fd\u6709\u6700\u4f18\u89e3\uff1a\u6ca1\u770b\u61c2
semaphore lock = 1;\nsemaphore eslot = BUFFER_SIZE; // \u7a7a\u95f2buffer\u7684\u6570\u91cf\nsemaphore fslot = 0;\nproducer(){\nwhile (true){\nwait (eslot); // if buffer is full. i.e. eslot == 0, wait. else eslot --\nwait (lock);\nadd_to_buffer(next_produced);\nsignal(lock);\nsignal(fslot); // fslot ++\n}\n}\nconsumer(){\nwhile(true){\nwait(fslot); // if buffer is empty. i.e. fslot == 0, wait. else fslot--\nwait(lock);\nnext_consumed = take_from_buffer();\nsignal(lock);\nsignal(eslot); // eslot ++\n}\n}\n
"},{"location":"CS/OS/process_syn/#62-reader-writer-problem","title":"6.2 Reader-Writer Problem","text":"\ud83d\udca1 \u5bf9\u4e00\u4e2a\u6570\u636e\uff0creaders\u8bfb\uff0cwriters\u8bfb\u548c\u5199 \u8bbe\u8ba1\u65b9\u6848\u4fdd\u8bc1\uff1a\u591a\u4e2areaders\u53ef\u4ee5\u540c\u65f6\u8bfb\u53d6\uff0c\u4f46\u662fwriter\u8fdb\u884c\u8bfb\u5199\u65f6\u4e0d\u80fd\u6709\u5176\u5b83writers\u548creaders\u3002 semaphore write_lock = 1;\nint reader_count = 0;\nsemaphore reader_count_lock = 1;\nsemaphore writer_first = 1;\nwriter() {\nwhile (true) {\nwait(writer_first);\nwait(write_lock);\nread_and_write();\nsignal(write_lock);\nsignal(writer_first);\n}\n}\nreader() {\nwhile (true) {\nwait(writer_first);\nwait(reader_count_lock);\nreader_count++;\nif (reader_count == 1)\nwait(write_lock);\nsignal(reader_count_lock);\nsignal(writer_first);\nread();\nwait(reader_count_lock);\nreader_count--;\nif (reader_count == 0)\nsignal(write_lock);\nsignal(reader_count_lock);\n}\n}\n
"},{"location":"CS/OS/process_syn/#63-dining-philosophers-problem","title":"6.3 Dining-Philosophers Problem","text":"\ud83d\udca1 5\u4e2a\u54f2\u5b66\u5bb6\u4e00\u8d77\u5403\u996d\u3002\u6bcf\u4e24\u4e2a\u54f2\u5b66\u5bb6\u4e4b\u95f4\u6709\u4e00\u6839\u7b77\u5b50\uff0c\u6bcf\u4e2a\u4eba\u4e00\u6b21\u53ef\u4ee5\u62ff\u8d77\u4e00\u6839\u7b77\u5b50\uff0c\u62ff\u5230\u4e24\u6839\u7b77\u5b50\u7684\u5c31\u53ef\u4ee5\u5403\u4e00\u6bb5\u65f6\u95f4\uff0c\u5403\u5b8c\u601d\u8003\u4e00\u6bb5\u65f6\u95f4\u3002  \u4e09\u79cd\u89e3\u51b3\u65b9\u6848\uff1a
\u662f\u6307\u591a\u4e2a\u8fdb\u7a0b\u56e0\u7ade\u4e89\u8d44\u6e90\u5bfc\u81f4\u7684\u4e00\u79cd\u50f5\u5c40\uff0c\u5373\u82e5\u5e72\u8fdb\u7a0b\u5404\u6301\u6709\u4e00\u4e9b\u8d44\u6e90\uff0c\u540c\u65f6\u7b49\u5f85\u83b7\u53d6\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u6301\u6709\u7684\u8d44\u6e90\uff0c\u5f62\u6210\u7684\u4e92\u76f8\u7b49\u5f85\u5c40\u9762\u3002
e.g.
\u4e24\u4e2a\u8fdb\u7a0b\uff0c\u4e24\u4e2a\u78c1\u76d8\u9a71\u52a8\u5668
semaphore first_mutex = 1;\nsemaphore second_mutex = 1;\nthread_one() {\nwait(first_mutex); // \u6301\u6709\u4e00\u4e2a\nwait(second_mutex); // \u60f3\u8981\u53e6\u4e00\u4e2a\n// ...\n}\nthread_two() {\nwait(second_mutex);\nwait(first_mutex);\n// ...\n}\n
\u53ef\u4ee5\u901a\u8fc7\u5206\u914d\u4f18\u5148\u7ea7\u6765\u89e3\u51b3\uff0c\u4f46\u662f\u4f18\u5148\u7ea7\u53ef\u80fd\u5bfc\u81f4starvation
"},{"location":"CS/OS/process_syn/#71-system-resource-allocation-graph","title":"7.1 \u8d44\u6e90\u5206\u914d\u56fe system resource-allocation graph","text":"\u662f\u4e00\u79cd\u5bf9\u7cfb\u7edf\u8d44\u6e90\u548c\u60f3\u4f7f\u7528\u8d44\u6e90\u7684\u5b9e\u4f8b\u8fdb\u884c\u5efa\u6a21\u7684\u89c4\u8303\u5316\u4f5c\u56fe\u6807\u51c6
\u5047\u8bbe\u6709m\u4e2a\u8d44\u6e90(resources) R1\u2026 Rm\uff0c\u6bcf\u79cd\u8d44\u6e90\u6709W\u4e2a\u5b9e\u4f8b\uff08instance\uff09\u3002\u5404\u4e2a\u6d3b\u52a8\u8fdb\u7a0bP1\u2026Pn\u4f1a\u5229\u7528\u8fd9\u4e9b\u8d44\u6e90\uff0c\u6bcf\u4e2a\u8d44\u6e90\u7684\u5229\u7528\u7531request, use, release\u4e09\u6b65\u7ec4\u6210\u3002 \u8d44\u6e90\u5206\u914d\u56fe\u662f\u4e00\u79cd\u6709\u5411\u56fe
\u6ca1\u6709\u73af\u4e00\u5b9a\u6ca1\u6709\u6b7b\u9501\uff0c\u6709\u73af\u53ef\u80fd\u4f46\u4e0d\u4e00\u5b9a\u6709\u6b7b\u9501\uff0c\u6709\u73af\u4e14\u6bcf\u4e2a\u8d44\u6e90\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u4e00\u5b9a\u6709\u6b7b\u9501\u3002
"},{"location":"CS/OS/process_syn/#72","title":"7.2 \u6b7b\u9501\u7684\u5fc5\u8981\u6761\u4ef6","text":"\ud83d\udca1 \u60f3\u8981\u7406\u89e3\u8fd9\u4e00\u5757\uff0c\u8bf7\u60f3\u8c61\u56db\u4e2a\u6210\u73af\u7684\u516c\u4ea4\u8def\u53e3\uff0c\u6bcf\u4e2a\u516c\u4ea4\u8def\u53e3\u90fd\u5835\u7740\u4e00\u6392\u60f3\u8981\u987a\u65f6\u9488\u524d\u884c\u7684\u8f66\u3002\u6bcf\u4e2a\u8f66\u90fd\u60f3\u8fdb\u5165\u4e0b\u4e00\u4e2a\u8def\u53e3\uff0c\u4f46\u662f\u6bcf\u4e2a\u8def\u53e3\u90fd\u88ab\u4e0a\u4e00\u8f86\u8f66\u5835\u7740\u4e0b\u9762\u56db\u70b9\u7684\u4ea4
\u5fc5\u8981\u6761\u4ef6\u2192\u6253\u7834\u4efb\u610f\u4e00\u70b9\u5c31\u80fd\u907f\u514d\u6b7b\u9501
\u5904\u7406\u6b7b\u9501\u7684\u56db\u79cd\u65b9\u6cd5
\u9884\u9632\u7684\u6838\u5fc3\u601d\u8def\u5c31\u662f\u6253\u7834\u5fc5\u8981\u6761\u4ef6\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u3002\u5206\u522b\u8ba8\u8bba\u56db\u4e2a\u6761\u4ef6\u5982\u4f55\u7834\u574f
\u907f\u514d\u6b7b\u9501\u5219\u662f\u9760\u9884\u6d4b\u8fdb\u7a0b\u672a\u6765\u9700\u8981\u4f7f\u7528\u54ea\u4e9b\u8d44\u6e90\u3001\u8d44\u6e90\u7684\u4f7f\u7528\u987a\u5e8f\u7b49\u3002\u7cfb\u7edf\u9700\u8981\u8bbe\u8ba1\u7b97\u6cd5\u8ba1\u7b97\u4e00\u4e0b\u6765\u907f\u514d\u3002\u6240\u4ee5\u65e2\u9700\u8981\u989d\u5916\u4fe1\u606f\uff0c\u53c8\u9700\u8981\u989d\u5916\u7b97\u6cd5\u3002
\u989d\u5916\u4fe1\u606f\u5305\u62ec
\u8d44\u6e90\u5206\u914d\u72b6\u6001resource allocation state:
\u8d44\u6e90\u5206\u914d\u56fe\u7b97\u6cd5\uff1a\u9002\u7528\u4e8e\u6bcf\u79cd\u8d44\u6e90\u90fd\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u7684\u60c5\u51b5
\u5728\u8d44\u6e90\u5206\u914d\u56fe\u4e0a\u52a0\u4e00\u79cd\u8fb9\uff1aclaim edge\u3002\u8868\u793a\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u9700\u8981\u67d0\u79cd\u8d44\u6e90\uff0c\u7528\u865a\u7ebf\u8868\u793a\u3002\u8f6c\u5316\u5173\u7cfb\u4e3a
graph TD\n claim_edge --\u9700\u6c42\u51fa\u73b0--> request_edge\n request_edge --\u4e0d\u4f1a\u51fa\u73b0\u73af\u7684\u8bdd\u5c31\u9700\u6c42\u6ee1\u8db3--> assignment_edge\n assignment_edge --\u8d44\u6e90\u91ca\u653e--> claim_edge\n
\u5b89\u5168\u72b6\u6001 Safe State
\u662f\u6307\u6309\u7167\u4e00\u5b9a\u987a\u5e8f\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u8d44\u6e90\uff0c\u540c\u65f6\u907f\u514d\u6b7b\u9501\u3002
\u5177\u4f53\u800c\u8a00\uff0c\u5982\u679c\u67d0\u4e2a\u8d44\u6e90\u6709A\u4e2a\u7a7a\u95f2\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u6d3b\u52a8\u8fdb\u7a0bPi\uff0c\u5404\u81ea\u6301\u6709Ci\u4e2a\u8be5\u8d44\u6e90\uff0c\u5e76\u4e14\u4ecd\u7136\u9700\u8981Di\u4e2a\u8d44\u6e90\u3002
\u5982\u679c\u4e00\u4e2a\u5e8f\u5217\u4f7f\u5f97\u5bf9\u4e8e\u4efb\u610fPi\uff0c\u90fd\u6709A+\\sum[j<i][j=1]{Ci} \u2265 Di, \u5219\u7cfb\u7edf\u5904\u4e8e\u5b89\u5168\u72b6\u6001\u3002
\u53ef\u4ee5\u7528\u5f52\u7eb3\u6cd5\u8bc1\u660e\uff1a\u5982\u679cPi\u7684\u9700\u6c42\u4e0d\u80fd\u88ab\u7acb\u523b\u6ee1\u8db3\uff0c\u53ea\u9700\u8981\u7b49\u5f85Pj | j<i \u5168\u90e8\u5b8c\u6210\u3002Pi\u5c31\u80fd\u83b7\u5f97\u6240\u9700\u8d44\u6e90 \u5b89\u5168\u72b6\u6001\u662f\u975e\u6b7b\u9501\u72b6\u6001\u7684\u5b50\u96c6
\u94f6\u884c\u5bb6\u7b97\u6cd5 Banker\u2019s Algorithm
\u901a\u8fc7available, max, allocation, need \u8fd9\u56db\u4e2a\u77e9\u9635\u523b\u753b\u4e00\u4e2a\u65f6\u95f4\u5185\u5404\u4e2a\u8fdb\u7a0b\u5bf9\u5404\u79cd\u8d44\u6e90\u7684\u6301\u6709\u548c\u9700\u6c42\u72b6\u51b5\uff0c\u4ee5\u53ca\u5f53\u524d\u7cfb\u7edf\u7684\u8d44\u6e90\u60c5\u51b5\u3002OS\u5e94\u4f7f\u7528\u8fd9\u4e9b\u6570\u636e\u5224\u65ad\u7cfb\u7edf\u662f\u5426\u5b89\u5168\u72b6\u6001\u3002
\u627e\u4e00\u4e2a\u5b89\u5168\u5e8f\u5217\u7684\u57fa\u672c\u601d\u8def\u662f\uff1a\u9009\u4e00\u4e2aneed\uff08\u7684\u6bcf\u4e00\u9879\u5bf9\u5e94\u5730\uff09\u5c0f\u4e8eavailable\uff08\u7684\u5bf9\u5e94\u9879\uff09\u7684\u8fdb\u7a0b\uff0c\u8fd0\u884c\u5b8c\u540e\u4f1a\u5c06allocation\u91ca\u653e\u56deavailable.
\u5047\u8bbe\u8fd9\u4e2a\u9700\u6c42\u88ab\u63a5\u53d7\u4e86\uff0c\u66f4\u65b0\u5bf9\u5e94\u7684need\uff0cavailable\uff0callocation
\u5728\u6b64\u72b6\u6001\u4e0b\u63a8\u6f14\u662f\u5426\u6709\u5408\u6cd5\u7684\u5b89\u5168\u5e8f\u5217\u3002
\u800c\u51b3\u5b9a\u4e00\u4e2a\u9700\u6c42\u662f\u5426\u5e94\u5f53\u88ab\u6ee1\u8db3\u7684\u65b9\u6848\u662f\uff0c\u5047\u8bbe\u88ab\u63a5\u53d7\u4e86\uff0c\u6839\u636e\u8be5\u9700\u6c42\u66f4\u65b0need\uff0cavailable\uff0callocation\uff0c\u5728\u6b64\u72b6\u6001\u63a8\u6f14\u662f\u5426\u6709\u5408\u6cd5\u7684\u5b89\u5168\u5e8f\u5217\u3002
"},{"location":"CS/OS/process_syn/#75","title":"7.5 \u68c0\u6d4b","text":"Single Instance Resources
wait-for graph\u6765\u89e3\u51b3
\u5728\u8fd9\u4e2a\u56fe\u91cc\u627e\u73af\uff0c\u7528\u62d3\u6251\u6392\u5e8f\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(V+E)\u7684\uff0c\u6700\u5dee\u60c5\u51b5\u4e0b\u662fO(n^2)\u7684\u3002 Multi-Instance Resources
\u7c7b\u4f3c\u94f6\u884c\u5bb6\u7b97\u6cd5\uff0c\u5982\u679c\u627e\u4e0d\u5230\u4efb\u4f55\u5b89\u5168\u5e8f\u5217\uff0c\u8bf4\u660e\u7cfb\u7edf\u5904\u4e8e\u6b7b\u9501\u3002
"},{"location":"CS/OS/process_syn/#76","title":"7.6 \u6062\u590d","text":"\u8fdb\u7a0b\u7ec8\u6b62Terminate deadlocked processes
\u5b83\u548c\u8d44\u6e90\u62a2\u5360\u7684\u533a\u522b\u4f3c\u4e4e\u662f\uff0c\u8fdb\u7a0b\u7ec8\u6b62\u4ee3\u4ef7\u975e\u5e38\u5927\uff0c\u5176\u4e00\u662f\u9700\u8981\u7ef4\u62a4\u7ec8\u6b62\u65f6\u7684\u72b6\u6001\uff0c\u5e76\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u4e00\u4e9b\u5185\u5bb9\uff0c\u5e76\u9700\u8981\u907f\u514d\u4ea7\u751f\u91cd\u590d\u7684\u526f\u4f5c\u7528\u3002
\u76f4\u63a5\u653e\u5f03\u6240\u6709\u8fdb\u7a0b\u82b1\u8d39\u4f1a\u5f88\u5927\u3002
\u53ef\u4ee5\u9009\u62e9\u6bcf\u6b21\u653e\u5f03\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u76f4\u5230\u6240\u6709\u6b7b\u9501\u73af\u89e3\u9664\u3002
\u5982\u4f55\u9009\u62e9\u653e\u5f03\u54ea\u4e2a\u8fdb\u7a0b\uff1a\u4e00\u7cfb\u5217\u6307\u6807
\u4e0d\u65ad\u62a2\u5360\u8d44\u6e90\u7ed9\u5176\u5b83\u8fdb\u7a0b\uff0c\u76f4\u5230\u6d88\u9664\u6b7b\u9501\u73af\u4e3a\u6b62
\u9700\u8981\u8003\u8651\u4e09\u4e2a\u95ee\u9898
\u672c\u7ae0\u8282\u5305\u62ec\u6df1\u5ea6\u5b66\u4e60\u7406\u8bba+\u5de5\u7a0b\u7b14\u8bb0\uff0c\u5df2\u5b8c\u6210\u4ee5\u4e0b\u5185\u5bb9 - \u5e38\u7528\u7684python\u547d\u4ee4 - \u5e38\u7528\u7684terminal\u547d\u4ee4 - NLP\u5b66\u4e60\u548c\u5de5\u7a0b\u7b14\u8bb0
"},{"location":"DL/NLPTech/bert_code/","title":"Note on BERT code","text":"Bert is an encoder-only Transformer structured model.
To implement a Bert, the following classes are required. - embedding: positional embedding, -
"},{"location":"DL/NLPTech/bert_code/#positional-embedding","title":"Positional Embedding","text":"class PositionalEmbedding(torch.nn.Module): \ndef __init__(self, d_model, max_len=128): \nsuper().__init__() \n# Compute the positional encodings once in log space. \npe = torch.zeros(max_len, d_model).float() \npe.require_grad = False \nfor pos in range(max_len): \n# for each dimension of the each position \nfor i in range(0, d_model, 2): \npe[pos, i] = math.sin(pos / (10000 ** ((2 * i)/d_model))) \npe[pos, i + 1] = math.cos(pos / (10000 ** ((2 * (i + 1))/d_model))) \n# include the batch size \nself.pe = pe.unsqueeze(0) \n# self.register_buffer('pe', pe) \ndef forward(self, x): \nreturn self.pe\n
"},{"location":"DL/NLPTech/bert_code/#bert-embedding","title":"Bert Embedding","text":"class BERTEmbedding(torch.nn.Module): \n\"\"\" \n BERT Embedding which is consisted with under features \n 1. TokenEmbedding : normal embedding matrix \n 2. PositionalEmbedding : adding positional information using sin, cos \n 2. SegmentEmbedding : adding sentence segment info, (sent_A:1, sent_B:2) \n sum of all these features are output of BERTEmbedding \n \"\"\" \ndef __init__(self, vocab_size, embed_size, seq_len=64, dropout=0.1): \n\"\"\" \n :param vocab_size: total vocab size \n :param embed_size: embedding size of token embedding \n :param dropout: dropout rate \n \"\"\" \nsuper().__init__() \nself.embed_size = embed_size \n# (m, seq_len) --> (m, seq_len, embed_size) \n# padding_idx is not updated during training, remains as fixed pad (0) \nself.token = torch.nn.Embedding(vocab_size, embed_size, padding_idx=0) \nself.segment = torch.nn.Embedding(3, embed_size, padding_idx=0) \nself.position = PositionalEmbedding(d_model=embed_size, max_len=seq_len) \nself.dropout = torch.nn.Dropout(p=dropout) \ndef forward(self, sequence, segment_label): \nx = self.token(sequence) + self.position(sequence) + self.segment(segment_label) \nreturn self.dropout(x)\n
"},{"location":"DL/NLPTech/bert_code/#multiheadattention","title":"MultiHeadAttention","text":"### attention layers \nclass MultiHeadedAttention(torch.nn.Module): \ndef __init__(self, heads, d_model, dropout=0.1): \nsuper(MultiHeadedAttention, self).__init__() \nassert d_model % heads == 0 \nself.d_k = d_model // heads \nself.heads = heads \nself.dropout = torch.nn.Dropout(dropout) \nself.query = torch.nn.Linear(d_model, d_model) \nself.key = torch.nn.Linear(d_model, d_model) \nself.value = torch.nn.Linear(d_model, d_model) \nself.output_linear = torch.nn.Linear(d_model, d_model) \ndef forward(self, query, key, value, mask): \n\"\"\" \n query, key, value of shape: (batch_size, max_len, d_model) \n mask of shape: (batch_size, 1, 1, max_words) \n \"\"\" \n# (batch_size, max_len, d_model) \nquery = self.query(query) \nkey = self.key(key) \nvalue = self.value(value) \n# (batch_size, max_len, d_model) --> (batch_size, max_len, h, d_k) --> (batch_size, h, max_len, d_k) \nquery = query.view(query.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \nkey = key.view(key.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \nvalue = value.view(value.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \n# (batch_size, h, max_len, d_k) matmul (batch_size, h, d_k, max_len) --> (batch_size, h, max_len, max_len) \nscores = torch.matmul(query, key.permute(0, 1, 3, 2)) / math.sqrt(query.size(-1)) \n# fill 0 mask with super small number so it wont affect the softmax weight \n# (batch_size, h, max_len, max_len) \nscores = scores.masked_fill(mask == 0, -1e9) \n# (batch_size, h, max_len, max_len) \n# softmax to put attention weight for all non-pad tokens \n# max_len X max_len matrix of attention \nweights = F.softmax(scores, dim=-1) \nweights = self.dropout(weights) \n# (batch_size, h, max_len, max_len) matmul (batch_size, h, max_len, d_k) --> (batch_size, h, max_len, d_k) \ncontext = torch.matmul(weights, value) \n# (batch_size, h, max_len, d_k) --> (batch_size, max_len, h, d_k) --> (batch_size, max_len, d_model) \ncontext = context.permute(0, 2, 1, 3).contiguous().view(context.shape[0], -1, self.heads * self.d_k) \n# (batch_size, max_len, d_model) \nreturn self.output_linear(context)\n
"},{"location":"DL/NLPTech/bert_code/#feedforward","title":"FeedForward","text":"class FeedForward(torch.nn.Module): \n\"Implements FFN equation.\" \ndef __init__(self, d_model, middle_dim=2048, dropout=0.1): \nsuper(FeedForward, self).__init__() \nself.fc1 = torch.nn.Linear(d_model, middle_dim) \nself.fc2 = torch.nn.Linear(middle_dim, d_model) \nself.dropout = torch.nn.Dropout(dropout) \nself.activation = torch.nn.GELU() \ndef forward(self, x): \nout = self.activation(self.fc1(x)) \nout = self.fc2(self.dropout(out)) \nreturn out \n
"},{"location":"DL/NLPTech/bert_code/#encoder-layer","title":"Encoder Layer","text":"class EncoderLayer(torch.nn.Module): \ndef __init__( \nself, \nd_model=768, \nheads=12, \nfeed_forward_hidden=768 * 4, \ndropout=0.1 \n): \nsuper(EncoderLayer, self).__init__() \nself.layernorm = torch.nn.LayerNorm(d_model) \nself.self_multihead = MultiHeadedAttention(heads, d_model) \nself.feed_forward = FeedForward(d_model, middle_dim=feed_forward_hidden) \nself.dropout = torch.nn.Dropout(dropout) \ndef forward(self, embeddings, mask): \n# embeddings: (batch_size, max_len, d_model) \n# encoder mask: (batch_size, 1, 1, max_len) \n# result: (batch_size, max_len, d_model) \ninteracted = self.dropout(self.self_multihead(embeddings, embeddings, embeddings, mask)) \n# residual layer \ninteracted = self.layernorm(interacted + embeddings) \n# bottleneck \nfeed_forward_out = self.dropout(self.feed_forward(interacted)) \nencoded = self.layernorm(feed_forward_out + interacted) \nreturn encoded\n
"},{"location":"DL/NLPTech/bert_code/#bert-model","title":"Bert model","text":"class BERT(torch.nn.Module): \n\"\"\" \n BERT model : Bidirectional Encoder Representations from Transformers. \n \"\"\" \ndef __init__(self, vocab_size, d_model=768, n_layers=12, heads=12, dropout=0.1): \n\"\"\" \n :param vocab_size: vocab_size of total words \n :param hidden: BERT model hidden size \n :param n_layers: numbers of Transformer blocks(layers) \n :param attn_heads: number of attention heads \n :param dropout: dropout rate \n \"\"\" \nsuper().__init__() \nself.d_model = d_model \nself.n_layers = n_layers \nself.heads = heads \n# paper noted they used 4 * hidden_size for ff_network_hidden_size \nself.feed_forward_hidden = d_model * 4 \n# embedding for BERT, sum of positional, segment, token embeddings \nself.embedding = BERTEmbedding(vocab_size=vocab_size, embed_size=d_model) \n# multi-layers transformer blocks, deep network \nself.encoder_blocks = torch.nn.ModuleList( \n[EncoderLayer(d_model, heads, d_model * 4, dropout) for _ in range(n_layers)]) \ndef forward(self, x, segment_info): \n# attention masking for padded token \n# (batch_size, 1, seq_len, seq_len) \nmask = (x > 0).unsqueeze(1).repeat(1, x.size(1), 1).unsqueeze(1) \n# embedding the indexed sequence to sequence of vectors \nx = self.embedding(x, segment_info) \n# running over multiple transformer blocks \nfor encoder in self.encoder_blocks: \nx = encoder.forward(x, mask) \nreturn x \nclass NextSentencePrediction(torch.nn.Module): \n\"\"\" \n 2-class classification model : is_next, is_not_next \n \"\"\" \ndef __init__(self, hidden): \n\"\"\" \n :param hidden: BERT model output size \n \"\"\" \nsuper().__init__() \nself.linear = torch.nn.Linear(hidden, 2) \nself.softmax = torch.nn.LogSoftmax(dim=-1) \ndef forward(self, x): \n# use only the first token which is the [CLS] \nreturn self.softmax(self.linear(x[:, 0])) \nclass MaskedLanguageModel(torch.nn.Module): \n\"\"\" \n predicting origin token from masked input sequence \n n-class classification problem, n-class = vocab_size \n \"\"\" \ndef __init__(self, hidden, vocab_size): \n\"\"\" \n :param hidden: output size of BERT model \n :param vocab_size: total vocab size \n \"\"\" \nsuper().__init__() \nself.linear = torch.nn.Linear(hidden, vocab_size) \nself.softmax = torch.nn.LogSoftmax(dim=-1) \ndef forward(self, x): \nreturn self.softmax(self.linear(x)) \n
class BERTLM(torch.nn.Module): \n\"\"\" \n BERT Language Model \n Next Sentence Prediction Model + Masked Language Model \n \"\"\" \ndef __init__(self, bert: BERT, vocab_size): \n\"\"\" \n :param bert: BERT model which should be trained \n :param vocab_size: total vocab size for masked_lm \n \"\"\" \nsuper().__init__() \nself.bert = bert \nself.next_sentence = NextSentencePrediction(self.bert.d_model) \nself.mask_lm = MaskedLanguageModel(self.bert.d_model, vocab_size) \ndef forward(self, x, segment_label): \nx = self.bert(x, segment_label) \nreturn self.next_sentence(x), self.mask_lm(x)\n
"},{"location":"DL/NLPTech/bert_code/#how-to-write-a-bert-trainer","title":"How to Write A BERT Trainer?","text":"In this section we will discuss how to train a BERT model. The loss function and optimizer are defined in the trainer as well.
criterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)\n
model = BERT()\nbatch = make_batch()\ninput_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(*batch))\n
for epoch in range(100):\n# initialize the parameters in optim with zero\noptimizer.zero_grad() \n# the arguments are input to the model\n# input_ids: \n# segment_ids:\n# masked pos:\nlogits_lm, logits_clsf = model(input_ids, segment_ids, masked_pos)\n# transpose to the masked_tokens' shape, and calculate the loss\nloss_lm = criterion(logits_lm.transpose(1, 2), masked_tokens) # for masked LM\n# calculate the average loss\nloss_lm = (loss_lm.float()).mean()\n# sentence classification loss\nloss_clsf = criterion(logits_clsf, isNext) # for sentence classification\nloss = loss_lm + loss_clsf\nif (epoch + 1) % 10 == 0:\nprint('Epoch:', '%04d' % (epoch + 1), 'cost =', '{:.6f}'.format(loss))\n# performs back propogation\nloss.backward()\n# the optimizer takes a step based on the computed gradients.\noptimizer.step()\n# Predict mask tokens\ninput_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(batch[0]))\nprint(text)\nprint([number_dict[w.item()] for w in input_ids[0] if number_dict[w.item()] != '[PAD]'])\nlogits_lm, logits_clsf = model(input_ids, segment_ids, masked_pos)\nlogits_lm = logits_lm.data.max(2)[1][0].data.numpy()\nprint('masked tokens list : ',[pos.item() for pos in masked_tokens[0] if pos.item() != 0])\nprint('predict masked tokens list : ',[pos for pos in logits_lm if pos != 0])\nlogits_clsf = logits_clsf.data.max(1)[1].data.numpy()[0]\nprint('isNext : ', True if isNext else False)\nprint('predict isNext : ',True if logits_clsf else False)\n
"},{"location":"DL/NLPTech/cs224n/","title":"CS224N \u7b14\u8bb0","text":"TODO
"},{"location":"DL/NLPTech/cs224n/#attention-based-nmt","title":"Attention-based NMT","text":""},{"location":"DL/NLPTech/cs224n/#convnet-based-nmt","title":"ConvNet-based NMT","text":""},{"location":"DL/NLPTech/cs224n/#final-project-implementing-a-model-to-challenge-sqaud","title":"Final project: implementing a model to challenge SQaUD","text":""},{"location":"DL/NLPTech/cs224n/#qanet","title":"QANet","text":""},{"location":"DL/NLPTech/cs231n/","title":"CS231n \u7b14\u8bb0","text":"TODO
"},{"location":"DL/NLPTech/cs231n/#pytorch","title":"Pytorch","text":"Output size calculation
output_size = (input_size + 2 * padding - kernel_size) / stride + 1\n
RuntimeError: mat2 must be a matrix, got 1-D tensor
torch.unsqueeze(fc_b, dim=1)\n
turns (10, ) list to (10, 1) tensor. "},{"location":"DL/NLPTech/cs231n/#self-supervised-learning","title":"Self-supervised Learning","text":""},{"location":"DL/NLPTech/cs231n/#gan","title":"GAN","text":""},{"location":"DL/NLPTech/cs231n/#transformer-image-caption","title":"Transformer Image Caption","text":""},{"location":"DL/NLPTech/gpt_code/","title":"Note on GPT code","text":"GPT's implementation involves only the decoder of the Transformer model.
class GPT(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.max_len = config.max_len\nself.tok_embed = nn.Embedding(\nconfig.vocab_size, embed_dim\n)\nself.pos_embed = nn.Parameter(\ntorch.zeros(1, config.max_len, embed_dim)\n)\nself.dropout = nn.Dropout(config.embed_dropout)\nself.blocks = nn.Sequential(\n*[DecoderBlock(config) for _ in range(config.num_blocks)]\n)\nself.ln = nn.LayerNorm(embed_dim)\nself.fc = nn.Linear(embed_dim, config.vocab_size)\ndef forward(self, x, target=None):\n# batch_size = x.size(0)\nseq_len = x.size(1)\nassert seq_len <= self.max_len, \"sequence longer than model capacity\"\ntok_embedding = self.tok_embed(x)\n# tok_embedding.shape == (batch_size, seq_len, embed_dim)\npos_embedding = self.pos_embed[:, :seq_len, :]\n# pos_embedding.shape == (1, seq_len, embed_dim)\nx = self.dropout(tok_embedding + pos_embedding)\nx = self.blocks(x)\nx = self.ln(x)\nx = self.fc(x)\n# x.shape == (batch_size, seq_len, vocab_size)\nreturn x\n
class DecoderBlock(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.ln1 = nn.LayerNorm(embed_dim)\nself.ln2 = nn.LayerNorm(embed_dim)\nself.attn = MultiheadAttention(config)\nself.ff = nn.Sequential(\nnn.Linear(embed_dim, embed_dim * 4),\nnn.GELU(),\nnn.Linear(embed_dim * 4, embed_dim),\nnn.Dropout(config.ff_dropout),\n)\ndef forward(self, x):\nx = x + self.attn(self.ln1(x))\nx = x + self.ff(self.ln2(x))\nreturn x\n
class MultiheadAttention(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.num_heads = config.num_heads\nassert embed_dim % self.num_heads == 0, \"invalid heads and embedding dimension configuration\"\nself.key = nn.Linear(embed_dim, embed_dim)\nself.value = nn.Linear(embed_dim, embed_dim)\nself.query = nn.Linear(embed_dim, embed_dim)\nself.proj = nn.Linear(embed_dim, embed_dim)\nself.attn_dropout = nn.Dropout(config.attn_dropout)\nself.proj_dropout = nn.Dropout(config.ff_dropout)\nself.register_buffer(\n\"mask\", \ntorch.tril(torch.ones(config.max_len, config.max_len))\n.unsqueeze(0).unsqueeze(0)\n)\ndef forward(self, x):\nbatch_size = x.size(0)\nseq_len = x.size(1)\n# x.shape == (batch_size, seq_len, embed_dim)\nk_t = self.key(x).reshape(batch_size, seq_len, self.num_heads, -1).permute(0, 2, 3, 1)\nv = self.value(x).reshape(batch_size, seq_len, self.num_heads, -1).transpose(1, 2)\nq = self.query(x).reshape(batch_size, seq_len, self.num_heads, -1).transpose(1, 2)\n# shape == (batch_size, num_heads, seq_len, head_dim)\nattn = torch.matmul(q, k_t) / math.sqrt(q.size(-1))\n# attn.shape == (batch_size, num_heads, seq_len, seq_len)\nmask = self.mask[:, :, :seq_len, :seq_len]\nattn = attn.masked_fill(mask == 0, float(\"-inf\"))\nattn = self.attn_dropout(attn)\n# attn.shape == (batch_size, num_heads, seq_len, seq_len)\nattn = F.softmax(attn, dim=-1)\ny = torch.matmul(attn, v)\n# y.shape == (batch_size, num_heads, seq_len, head_dim)\ny = y.transpose(1, 2)\n# y.shape == (batch_size, seq_len, num_heads, head_dim)\ny = y.reshape(batch_size, seq_len, -1)\n# y.shape == (batch_size, seq_len, embed_dim)\ny = self.proj_dropout(self.proj(y))\nreturn y\n
Finally we will see its default configuration.
class GPTConfig:\nattn_dropout = 0.1\nembed_dropout = 0.1\nff_dropout = 0.1\ndef __init__(\nself, vocab_size, max_len, **kwargs\n):\nself.vocab_size = vocab_size\nself.max_len = max_len\nfor key, value in kwargs.items():\nsetattr(self, key, value)\nclass GPT1Config(GPTConfig):\nnum_heads = 12\nnum_blocks = 12\nembed_dim = 768\n
"},{"location":"DL/NLPTech/llama_code/","title":"Note on LLaMa Code","text":""},{"location":"DL/NLPTech/llama_code/#introduction","title":"Introduction","text":"This note only focuses on the classes and eliminates all other packages or data processing lines.
LLaMA is a decoder-only Transformer architecture. To implement a LLaMA, the following modules will be applied. - class LLaMA: generation - model utils: RMSNorm, Attention, FeedForward, TransformerBlock, Transformer
LLaMA makes 3 main improvements to the Transformer architecture: RMSNorm, RoPE, and SwiGLU.
"},{"location":"DL/NLPTech/llama_code/#rmsnorm","title":"RMSNorm","text":"Root mean square layer norm, proposed in 2019. Its capability in handling re-centering (removing mean) and re-scaling (maintaining square) of both inputs and weight matrix can stabilize training and boost model convergence. The RMSNorm only focuses on re-scaling invariance and regularizes the summed inputs according to the root mean square statistics. $$ \\bar{a_i} = \\frac{a_i}{RMS(a)}g_i, \\space where \\space RMS(a) = \\sqrt{\\frac{1}{n}\\sum_{i=1}^{n}{a^2_i}} $$
class RMSNorm(torch.nn.Module):\ndef __init__(self, dim: int, eps: float = 1e-6):\nsuper().__init__()\nself.eps = eps\nself.weight = nn.Parameter(torch.ones(dim))\ndef _norm(self, x):\nreturn x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)\ndef forward(self, x):\noutput = self._norm(x.float()).type_as(x)\nreturn output * self.weight\n
"},{"location":"DL/NLPTech/llama_code/#attention","title":"Attention","text":"def reshape_for_broadcast(freqs_cis: torch.Tensor, x: torch.Tensor):\nndim = x.ndim\nassert 0 <= 1 < ndim\nassert freqs_cis.shape == (x.shape[1], x.shape[-1])\nshape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]\nreturn freqs_cis.view(*shape)\n
def apply_rotary_emb(\nxq: torch.Tensor,\nxk: torch.Tensor,\nfreqs_cis: torch.Tensor,\n) -> Tuple[torch.Tensor, torch.Tensor]:\nxq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))\nxk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))\nfreqs_cis = reshape_for_broadcast(freqs_cis, xq_)\nxq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)\nxk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)\nreturn xq_out.type_as(xq), xk_out.type_as(xk)\n
def repeat_kv(x: torch.Tensor, n_rep: int) -> torch.Tensor:\n\"\"\"torch.repeat_interleave(x, dim=2, repeats=n_rep)\"\"\"\nbs, slen, n_kv_heads, head_dim = x.shape\nif n_rep == 1:\nreturn x\nreturn (\nx[:, :, :, None, :]\n.expand(bs, slen, n_kv_heads, n_rep, head_dim)\n.reshape(bs, slen, n_kv_heads * n_rep, head_dim)\n)\n
class Attention(nn.Module):\ndef __init__(self, args: ModelArgs):\nsuper().__init__()\nself.n_kv_heads = args.n_heads if args.n_kv_heads is None else args.n_kv_heads\nmodel_parallel_size = fs_init.get_model_parallel_world_size()\nself.n_local_heads = args.n_heads // model_parallel_size\nself.n_local_kv_heads = self.n_kv_heads // model_parallel_size\nself.n_rep = self.n_local_heads // self.n_local_kv_heads\nself.head_dim = args.dim // args.n_heads\nself.wq = ColumnParallelLinear(\nargs.dim,\nargs.n_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wk = ColumnParallelLinear(\nargs.dim,\nself.n_kv_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wv = ColumnParallelLinear(\nargs.dim,\nself.n_kv_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wo = RowParallelLinear(\nargs.n_heads * self.head_dim,\nargs.dim,\nbias=False,\ninput_is_parallel=True,\ninit_method=lambda x: x,\n)\nself.cache_k = torch.zeros(\n(\nargs.max_batch_size,\nargs.max_seq_len,\nself.n_local_kv_heads,\nself.head_dim,\n)\n).cuda()\nself.cache_v = torch.zeros(\n(\nargs.max_batch_size,\nargs.max_seq_len,\nself.n_local_kv_heads,\nself.head_dim,\n)\n).cuda()\ndef forward(\nself,\nx: torch.Tensor,\nstart_pos: int,\nfreqs_cis: torch.Tensor,\nmask: Optional[torch.Tensor],\n):\nbsz, seqlen, _ = x.shape\nxq, xk, xv = self.wq(x), self.wk(x), self.wv(x)\nxq = xq.view(bsz, seqlen, self.n_local_heads, self.head_dim)\nxk = xk.view(bsz, seqlen, self.n_local_kv_heads, self.head_dim)\nxv = xv.view(bsz, seqlen, self.n_local_kv_heads, self.head_dim)\nxq, xk = apply_rotary_emb(xq, xk, freqs_cis=freqs_cis)\nself.cache_k = self.cache_k.to(xq)\nself.cache_v = self.cache_v.to(xq)\nself.cache_k[:bsz, start_pos : start_pos + seqlen] = xk\nself.cache_v[:bsz, start_pos : start_pos + seqlen] = xv\nkeys = self.cache_k[:bsz, : start_pos + seqlen]\nvalues = self.cache_v[:bsz, : start_pos + seqlen]\n# repeat k/v heads if n_kv_heads < n_heads\nkeys = repeat_kv(keys, self.n_rep) # (bs, seqlen, n_local_heads, head_dim)\nvalues = repeat_kv(values, self.n_rep) # (bs, seqlen, n_local_heads, head_dim)\nxq = xq.transpose(1, 2) # (bs, n_local_heads, seqlen, head_dim)\nkeys = keys.transpose(1, 2)\nvalues = values.transpose(1, 2)\nscores = torch.matmul(xq, keys.transpose(2, 3)) / math.sqrt(self.head_dim)\nif mask is not None:\nscores = scores + mask # (bs, n_local_heads, seqlen, cache_len + seqlen)\nscores = F.softmax(scores.float(), dim=-1).type_as(xq)\noutput = torch.matmul(scores, values) # (bs, n_local_heads, seqlen, head_dim)\noutput = output.transpose(1, 2).contiguous().view(bsz, seqlen, -1)\nreturn self.wo(output)\n
"},{"location":"DL/NLPTech/llama_code/#feedforward","title":"FeedForward","text":"class FeedForward(nn.Module):\ndef __init__(\nself,\ndim: int,\nhidden_dim: int,\nmultiple_of: int,\nffn_dim_multiplier: Optional[float],\n):\nsuper().__init__()\nhidden_dim = int(2 * hidden_dim / 3)\n# custom dim factor multiplier\nif ffn_dim_multiplier is not None:\nhidden_dim = int(ffn_dim_multiplier * hidden_dim)\nhidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)\nself.w1 = ColumnParallelLinear(\ndim, hidden_dim, bias=False, gather_output=False, init_method=lambda x: x\n)\nself.w2 = RowParallelLinear(\nhidden_dim, dim, bias=False, input_is_parallel=True, init_method=lambda x: x\n)\nself.w3 = ColumnParallelLinear(\ndim, hidden_dim, bias=False, gather_output=False, init_method=lambda x: x\n)\ndef forward(self, x):\nreturn self.w2(F.silu(self.w1(x)) * self.w3(x))\n
"},{"location":"DL/NLPTech/llama_code/#transformerblock","title":"TransformerBlock","text":"class TransformerBlock(nn.Module):\ndef __init__(self, layer_id: int, args: ModelArgs):\nsuper().__init__()\nself.n_heads = args.n_heads\nself.dim = args.dim\nself.head_dim = args.dim // args.n_heads\nself.attention = Attention(args)\nself.feed_forward = FeedForward(\ndim=args.dim,\nhidden_dim=4 * args.dim,\nmultiple_of=args.multiple_of,\nffn_dim_multiplier=args.ffn_dim_multiplier,\n)\nself.layer_id = layer_id\nself.attention_norm = RMSNorm(args.dim, eps=args.norm_eps)\nself.ffn_norm = RMSNorm(args.dim, eps=args.norm_eps)\ndef forward(\nself,\nx: torch.Tensor,\nstart_pos: int,\nfreqs_cis: torch.Tensor,\nmask: Optional[torch.Tensor],\n):\n# Add & Norm. add an highway to the attention block.\nh = x + self.attention.forward(\nself.attention_norm(x), start_pos, freqs_cis, mask\n)\n# feedforward and addition\nout = h + self.feed_forward.forward(self.ffn_norm(h))\nreturn out\n
"},{"location":"DL/NLPTech/llama_code/#transformer","title":"Transformer","text":"We implement several utility functions before implementing the transformer model.
def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0):\nfreqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))\nt = torch.arange(end, device=freqs.device) # type: ignore\nfreqs = torch.outer(t, freqs).float() # type: ignore\nfreqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64\nreturn freqs_cis\n
class Transformer(nn.Module):\ndef __init__(self, params: ModelArgs):\nsuper().__init__()\nself.params = params\nself.vocab_size = params.vocab_size\nself.n_layers = params.n_layers\nself.tok_embeddings = ParallelEmbedding(\nparams.vocab_size, params.dim, init_method=lambda x: x\n)\nself.layers = torch.nn.ModuleList()\nfor layer_id in range(params.n_layers):\nself.layers.append(TransformerBlock(layer_id, params))\nself.norm = RMSNorm(params.dim, eps=params.norm_eps)\nself.output = ColumnParallelLinear(\nparams.dim, params.vocab_size, bias=False, init_method=lambda x: x\n)\nself.freqs_cis = precompute_freqs_cis(\nself.params.dim // self.params.n_heads, self.params.max_seq_len * 2\n)\n@torch.inference_mode()\ndef forward(self, tokens: torch.Tensor, start_pos: int):\n_bsz, seqlen = tokens.shape\nh = self.tok_embeddings(tokens)\nself.freqs_cis = self.freqs_cis.to(h.device)\nfreqs_cis = self.freqs_cis[start_pos : start_pos + seqlen]\nmask = None\nif seqlen > 1:\nmask = torch.full(\n(1, 1, seqlen, seqlen), float(\"-inf\"), device=tokens.device\n)\nmask = torch.triu(mask, diagonal=start_pos + 1).type_as(h)\nfor layer in self.layers:\nh = layer(h, start_pos, freqs_cis, mask)\nh = self.norm(h)\noutput = self.output(h).float()\nreturn output\n
"},{"location":"DL/NLPTech/llama_code/#llama","title":"LLaMa","text":"Let's finally see the default model args.
@dataclass\nclass ModelArgs:\ndim: int = 4096\nn_layers: int = 32\nn_heads: int = 32\nn_kv_heads: Optional[int] = None\nvocab_size: int = -1 # defined later by tokenizer\nmultiple_of: int = 256 # make SwiGLU hidden layer size multiple of large power of 2\nffn_dim_multiplier: Optional[float] = None\nnorm_eps: float = 1e-5\nmax_batch_size: int = 32\nmax_seq_len: int = 2048\n
class Llama:\n@staticmethod\ndef build(\nckpt_dir: str,\ntokenizer_path: str,\nmax_seq_len: int,\nmax_batch_size: int,\nmodel_parallel_size: Optional[int] = None,\n) -> \"Llama\":\nif not torch.distributed.is_initialized():\ntorch.distributed.init_process_group(\"nccl\")\nif not model_parallel_is_initialized():\nif model_parallel_size is None:\nmodel_parallel_size = int(os.environ.get(\"WORLD_SIZE\", 1))\ninitialize_model_parallel(model_parallel_size)\nlocal_rank = int(os.environ.get(\"LOCAL_RANK\", 0))\ntorch.cuda.set_device(local_rank)\n# seed must be the same in all processes\ntorch.manual_seed(1)\nif local_rank > 0:\nsys.stdout = open(os.devnull, \"w\")\nstart_time = time.time()\ncheckpoints = sorted(Path(ckpt_dir).glob(\"*.pth\"))\nassert len(checkpoints) > 0, f\"no checkpoint files found in {ckpt_dir}\"\nassert model_parallel_size == len(\ncheckpoints\n), f\"Loading a checkpoint for MP={len(checkpoints)} but world size is {model_parallel_size}\"\nckpt_path = checkpoints[get_model_parallel_rank()]\ncheckpoint = torch.load(ckpt_path, map_location=\"cpu\")\nwith open(Path(ckpt_dir) / \"params.json\", \"r\") as f:\nparams = json.loads(f.read())\nmodel_args: ModelArgs = ModelArgs(\nmax_seq_len=max_seq_len,\nmax_batch_size=max_batch_size,\n**params,\n)\ntokenizer = Tokenizer(model_path=tokenizer_path)\nmodel_args.vocab_size = tokenizer.n_words\ntorch.set_default_tensor_type(torch.cuda.HalfTensor)\nmodel = Transformer(model_args)\nmodel.load_state_dict(checkpoint, strict=False)\nprint(f\"Loaded in {time.time() - start_time:.2f} seconds\")\nreturn Llama(model, tokenizer)\ndef __init__(self, model: Transformer, tokenizer: Tokenizer):\nself.model = model\nself.tokenizer = tokenizer\n@torch.inference_mode()\ndef generate(\nself,\nprompt_tokens: List[List[int]],\nmax_gen_len: int,\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nlogprobs: bool = False,\necho: bool = False,\n) -> Tuple[List[List[int]], Optional[List[List[float]]]]:\nparams = self.model.params\nbsz = len(prompt_tokens)\nassert bsz <= params.max_batch_size, (bsz, params.max_batch_size)\nmin_prompt_len = min(len(t) for t in prompt_tokens)\nmax_prompt_len = max(len(t) for t in prompt_tokens)\nassert max_prompt_len <= params.max_seq_len\ntotal_len = min(params.max_seq_len, max_gen_len + max_prompt_len)\npad_id = self.tokenizer.pad_id\ntokens = torch.full((bsz, total_len), pad_id, dtype=torch.long, device=\"cuda\")\nfor k, t in enumerate(prompt_tokens):\ntokens[k, : len(t)] = torch.tensor(t, dtype=torch.long, device=\"cuda\")\nif logprobs:\ntoken_logprobs = torch.zeros_like(tokens, dtype=torch.float)\nprev_pos = 0\neos_reached = torch.tensor([False] * bsz, device=\"cuda\")\ninput_text_mask = tokens != pad_id\nfor cur_pos in range(min_prompt_len, total_len):\nlogits = self.model.forward(tokens[:, prev_pos:cur_pos], prev_pos)\nif logprobs:\ntoken_logprobs[:, prev_pos + 1 : cur_pos + 1] = -F.cross_entropy(\ninput=logits.transpose(1, 2),\ntarget=tokens[:, prev_pos + 1 : cur_pos + 1],\nreduction=\"none\",\nignore_index=pad_id,\n)\nif temperature > 0:\nprobs = torch.softmax(logits[:, -1] / temperature, dim=-1)\nnext_token = sample_top_p(probs, top_p)\nelse:\nnext_token = torch.argmax(logits[:, -1], dim=-1)\nnext_token = next_token.reshape(-1)\n# only replace token if prompt has already been generated\nnext_token = torch.where(\ninput_text_mask[:, cur_pos], tokens[:, cur_pos], next_token\n)\ntokens[:, cur_pos] = next_token\neos_reached |= (~input_text_mask[:, cur_pos]) & (\nnext_token == self.tokenizer.eos_id\n)\nprev_pos = cur_pos\nif all(eos_reached):\nbreak\nif logprobs:\ntoken_logprobs = token_logprobs.tolist()\nout_tokens, out_logprobs = [], []\nfor i, toks in enumerate(tokens.tolist()):\n# cut to max gen len\nstart = 0 if echo else len(prompt_tokens[i])\ntoks = toks[start : len(prompt_tokens[i]) + max_gen_len]\nprobs = None\nif logprobs:\nprobs = token_logprobs[i][start : len(prompt_tokens[i]) + max_gen_len]\n# cut to eos tok if any\nif self.tokenizer.eos_id in toks:\neos_idx = toks.index(self.tokenizer.eos_id)\ntoks = toks[:eos_idx]\nprobs = probs[:eos_idx] if logprobs else None\nout_tokens.append(toks)\nout_logprobs.append(probs)\nreturn (out_tokens, out_logprobs if logprobs else None)\ndef text_completion(\nself,\nprompts: List[str],\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nmax_gen_len: Optional[int] = None,\nlogprobs: bool = False,\necho: bool = False,\n) -> List[CompletionPrediction]:\nif max_gen_len is None:\nmax_gen_len = self.model.params.max_seq_len - 1\nprompt_tokens = [self.tokenizer.encode(x, bos=True, eos=False) for x in prompts]\ngeneration_tokens, generation_logprobs = self.generate(\nprompt_tokens=prompt_tokens,\nmax_gen_len=max_gen_len,\ntemperature=temperature,\ntop_p=top_p,\nlogprobs=logprobs,\necho=echo,\n)\nif logprobs:\nreturn [\n{\n\"generation\": self.tokenizer.decode(t),\n\"tokens\": [self.tokenizer.decode(x) for x in t],\n\"logprobs\": logprobs_i,\n}\nfor t, logprobs_i in zip(generation_tokens, generation_logprobs)\n]\nreturn [{\"generation\": self.tokenizer.decode(t)} for t in generation_tokens]\ndef chat_completion(\nself,\ndialogs: List[Dialog],\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nmax_gen_len: Optional[int] = None,\nlogprobs: bool = False,\n) -> List[ChatPrediction]:\nif max_gen_len is None:\nmax_gen_len = self.model.params.max_seq_len - 1\nprompt_tokens = []\nunsafe_requests = []\nfor dialog in dialogs:\nunsafe_requests.append(\nany([tag in msg[\"content\"] for tag in SPECIAL_TAGS for msg in dialog])\n)\nif dialog[0][\"role\"] == \"system\":\ndialog = [\n{\n\"role\": dialog[1][\"role\"],\n\"content\": B_SYS\n+ dialog[0][\"content\"]\n+ E_SYS\n+ dialog[1][\"content\"],\n}\n] + dialog[2:]\nassert all([msg[\"role\"] == \"user\" for msg in dialog[::2]]) and all(\n[msg[\"role\"] == \"assistant\" for msg in dialog[1::2]]\n), (\n\"model only supports 'system', 'user' and 'assistant' roles, \"\n\"starting with 'system', then 'user' and alternating (u/a/u/a/u...)\"\n)\ndialog_tokens: List[int] = sum(\n[\nself.tokenizer.encode(\nf\"{B_INST} {(prompt['content']).strip()} {E_INST} {(answer['content']).strip()} \",\nbos=True,\neos=True,\n)\nfor prompt, answer in zip(\ndialog[::2],\ndialog[1::2],\n)\n],\n[],\n)\nassert (\ndialog[-1][\"role\"] == \"user\"\n), f\"Last message must be from user, got {dialog[-1]['role']}\"\ndialog_tokens += self.tokenizer.encode(\nf\"{B_INST} {(dialog[-1]['content']).strip()} {E_INST}\",\nbos=True,\neos=False,\n)\nprompt_tokens.append(dialog_tokens)\ngeneration_tokens, generation_logprobs = self.generate(\nprompt_tokens=prompt_tokens,\nmax_gen_len=max_gen_len,\ntemperature=temperature,\ntop_p=top_p,\nlogprobs=logprobs,\n)\nif logprobs:\nreturn [\n{\n\"generation\": {\n\"role\": \"assistant\",\n\"content\": self.tokenizer.decode(t)\nif not unsafe\nelse UNSAFE_ERROR,\n},\n\"tokens\": [self.tokenizer.decode(x) for x in t],\n\"logprobs\": logprobs_i,\n}\nfor t, logprobs_i, unsafe in zip(\ngeneration_tokens, generation_logprobs, unsafe_requests\n)\n]\nreturn [\n{\n\"generation\": {\n\"role\": \"assistant\",\n\"content\": self.tokenizer.decode(t) if not unsafe else UNSAFE_ERROR,\n}\n}\nfor t, unsafe in zip(generation_tokens, unsafe_requests)\n]\ndef sample_top_p(probs, p):\nprobs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)\nprobs_sum = torch.cumsum(probs_sort, dim=-1)\nmask = probs_sum - probs_sort > p\nprobs_sort[mask] = 0.0\nprobs_sort.div_(probs_sort.sum(dim=-1, keepdim=True))\nnext_token = torch.multinomial(probs_sort, num_samples=1)\nnext_token = torch.gather(probs_idx, -1, next_token)\nreturn next_token\n
"},{"location":"DL/NLPTech/llama_code/#references","title":"References","text":"facebookresearch/llama: Inference code for LLaMA models (github.com)
"},{"location":"DL/NLPTech/ml_cheatsheet/","title":"ML\u516b\u80a1 ero to hero","text":""},{"location":"DL/NLPTech/ml_cheatsheet/#ml","title":"ML","text":"\u8bbe\u8ba1\u6a21\u578b\u7684\u65f6\u5019\uff0c\u5982\u4f55\u786e\u5b9aembedding\u7684size? embedding\u7684\u5927\u5c0f\u4e00\u822c\u662f\u4e00\u4e2a\u7ecf\u9a8c\u503c\uff0c\u5047\u8bbeembedding\u5bf9\u5e94\u7684\u539f\u59cbfeature\u7684\u53d6\u503c\u6570\u91cf\u4e3an\uff0c\u5219\u4e00\u822c\u4f1a\u91c7\u7528\\(log_2(n)\\)\u6216\u8005\\(k\\sqrt[4]{n} (k<16)\\)\u6765\u505a\u521d\u59cb\u7684size\uff0c\u7136\u540e2\u500d\u6269\u5927\u6216\u7f29\u5c0f\u3002
Self Attention\u7684\u8868\u8fbe\u5f0f \\(\\(Softmax(\\frac{QK^T}{\\sqrt{d_k}})V\\)\\) \u5bf9QK\u8fdb\u884cscaling\u7684\u76ee\u7684\u662f\uff0cscaling\u540e\u8fdb\u884csoftmax\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u53d8\u5f97\u66f4\u597d\u3002\u6570\u503c\u4f1a\u8fdb\u5165\u654f\u611f\u533a\u95f4\uff0c\u9632\u6b62\u68af\u5ea6\u6d88\u5931\uff0c\u8ba9\u6a21\u578b\u66f4\u5bb9\u6613\u8bad\u7ec3\u3002
attention\u8ba1\u7b97\u65b9\u5f0f\u53ca\u53c2\u6570\u91cf\uff1f\u9ed8\u5199multi-headed attention? \u7b80\u7ea6\u7248
import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport math\nclass MultiHeadAttention(nn.Module):\ndef __init__(self, d_model, num_heads):\nsuper(MultiHeadAttention, self).__init__()\nself.num_heads = num_heads\nself.d_model = d_model # d_model is a emphirical number\nassert d_model % self.num_heads == 0\n# define the dimension of each head or subspace\nself.d_k = d_model // self.num_heads\n# these are still of dimension d_model. They will be split into numbers\nself.W_q = nn.Linear(d_model, d_model)\nself.W_k = nn.Linear(d_model, d_model)\nself.W_v = nn.Linear(d_model, d_model)\n# Output of all sub-layers need to be of dimension d_model\nself.W_o = nn.Linear(d_model, d_model)\ndef scaled_dot_product_attention(self, Q, K, V, mask = None):\nbatch_size = Q.size(0) # layernorm?\nK_length = K.size(-2) # \n# scaling by d_k so that the soft(arg)max doesn't explode\nQK = torch.matmul(Q, K.transpose(-2, -1) / math.sqrt(self.d_k))# matrix product of tensors\n# apply the mask\nif mask is not None: # mask is a matrix with 0 to be masked\nQK = QK.maksed_fill(mask.to(QK.type) == 0, float('-inf'))\n# calculate the attention weights (softmax over the lask dimension)\nweights = F.softmax(QK, dim = -1)\n# apply the self attention to the values\nattention = torch.matmul(weights, V)\nreturn attention, weights\ndef split_heads(self, x, batch_size):\n\"\"\"\n The original tensor \n with dimension batch_size * seq_length * d_model is divided by num_heads\n d_model // num_heads = d_k\n so now batch_size * seq_length * d_k\n \"\"\"\nreturn x.view(batch_size, -1, self.num_heads, self.d_k).transpose(1, 2)\ndef forward(self, q, k, v, mask = None):\nbatch_size = q.size(0)\n# linear layers\nq = self.W_q(q)\nk = self.W_k(k)\nv = self.W_v(v)\n# split into multiple heads\nq = self.split_heads(q, batch_size)\nk = self.split_heads(k, batch_size)\nv = self.split_heads(v, batch_size)\n# self attention\nscores, weights = self.scaled_dot_product_attention(q, k, v, mask)\n# concatenate heads\nconcat = scores.transpose(1, 2).contiguous().view(batch_size, -1, self.d_model())\n# final linear layer\noutput = self.W_o(concat)\nreturn output, weights\n
Multi-headed attention \u5f97\u5230\u7684\u662f\u4e24\u4e2a\u8f93\u51fa\uff0c\u4e00\u4e2aoutput\uff081 * d_model\uff09\u662f\u7ebf\u6027\u7684attention\u7ed3\u679c\uff0c\u4e00\u4e2aweight\u77e9\u9635\u662f\uff1f\u7ef4\u7684. \u51fa\u4e8e\u8fd0\u7b97\u901f\u5ea6\u7684\u8003\u8651\uff0c\u6211\u4eec\u8ba4\u4e3a\u201c\u4e00\u6b21\u5927\u7684\u77e9\u9635\u4e58\u6cd5\u7684\u6267\u884c\u901f\u5ea6\u6bd4\u591a\u6b21\u8f83\u5c0f\u7684\u77e9\u9635\u4e58\u6cd5\u66f4\u5feb\u201d\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728__init__\u4e2d self.qkv = nn.Linear(d_model, 3 * d_model)\n
\u5728forward\u65b9\u6cd5\u4e2d qkv = self.qkv(x)\nq, k, v = torch.split(qkv, self.d_model, dim = -1) # split into three tensors\n
Lora\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\uff1f \uff081\uff09\u57fa\u4e8e\u4f4e\u79e9\u7684\u5fae\u8c03\u53ef\u80fd\u4e0dalways work\uff0c\u6bd4\u5982finetune\u4e0epretrain\u4efb\u52a1\u7684gap\u8fc7\u5927\u7684\u65f6\u5019\uff08\u5982\uff1a\u4e2d\u82f1\u5dee\u5f02\uff09\u3002\u5f53\u7136\u8fd9\u4e00\u70b9\u5728LLM\u65f6\u4ee3\u53ef\u80fd\u5e76\u4e0d\u7a81\u51fa\uff0c\u56e0\u4e3a\u6211\u4eec\u8ba4\u4e3aLLM\u5728\u4e0e\u8bad\u7ec3\u9636\u6bb5\u5df2\u7ecfget\u4e86\u57fa\u672c\u6240\u6709\u7684\u77e5\u8bc6\uff0cfinetune\u4e5f\u53ea\u662f\u5728\u5fae\u8c03\u683c\u5f0f\uff0c\u56e0\u6b64\u53ef\u80fd\u4e0d\u4f1a\u6709\u4e0a\u8ff0gap\u8fc7\u5927\u7684\u60c5\u51b5\u3002 \uff082\uff09\u7528LoRA\u65f6\u4e5f\u8981\u8bbe\u7f6er\u548ctarget module\u7b49\uff0c\u8fd9\u90e8\u5206\u8d85\u53c2\u7684\u8bbe\u7f6e\u9700\u8981\u8003\u8651\u3002
\u5404\u79cdnorm\u65b9\u5f0f\u7684\u4f18\u7f3a\u70b9 \u5e38\u89c1\u7684norm\u65b9\u5f0f\u6709\u4ee5\u4e0b\u56db\u79cd\uff1a Batch norm: \u628a\u6bcf\u4e2abatch\u4e2d\u6bcf\u53e5\u8bdd\u76f8\u540c\u4f4d\u7f6e\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002\u5728\u5904\u7406\u5e8f\u5217\u6570\u636e\uff08\u5982\u6587\u672c\uff09\u65f6\uff0cbatch norm\u53ef\u80fd\u4e0d\u4f1a\u8868\u73b0\u5f88\u597d\uff0c\u56e0\u4e3a\u5e8f\u5217\u6570\u636e\u901a\u5e38\u957f\u5ea6\u4e0d\u4e00\uff0c\u5e76\u4e14\u4e00\u6b21\u8bad\u7ec3\u4e2dbatch\u7684\u53e5\u5b50\u957f\u5ea6\u53ef\u80fd\u4f1a\u6709\u5f88\u5927\u7684\u5dee\u5f02\uff0c\u6b64\u5916\uff0cbatch norm\u5bf9batch\u7684\u5927\u5c0f\u4e5f\u975e\u5e38\u654f\u611f\uff0c\u5bf9\u4e8e\u8f83\u5c0f\u7684batch\u5927\u5c0f\uff0cbatch norm\u53ef\u80fd\u4e5f\u4f1a\u8868\u73b0\u4e0d\u597d\uff0c\u56e0\u4e3a\u6bcf\u4e2abatch\u7684\u7edf\u8ba1\u7279\u6027\u53ef\u80fd\u4f1a\u6709\u8f83\u5927\u6ce2\u52a8\u3002
Layer norm: \u5728\u6bcf\u4e2a\u53e5\u5b50\u4e2d\u8fdb\u884c\u5f52\u4e00\u5316\u3002Layer norm\u662f\u5bf9\u6bcf\u4e2a\u6837\u672c\u8fdb\u884c\u5f52\u4e00\u5316\uff0c\u56e0\u6b64\u5b83\u4eec\u5bf9batch\u5927\u5c0f\u4e0d\u654f\u611f\uff0c\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u5904\u7406\u5e8f\u5217\u6570\u636e\u7684\u65f6\u5019\u8868\u73b0\u5f97\u66f4\u597d\uff0c\u53e6\u5916layer norm\u5728\u5904\u7406\u4e0d\u540c\u957f\u5ea6\u7684\u5e8f\u5217\u65f6\u4e5f\u66f4\u7075\u6d3b\u3002
Instance norm: \u6bcf\u4e00\u4e2a\u5b57\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002\u4f18\u70b9\u662f\u5bf9\u6bcf\u4e2a\u6837\u672c\u7684\u6bcf\u4e2a\u7279\u5f81\u8fdb\u884c\u5f52\u4e00\u5316\uff0c\u56e0\u6b64\u53ef\u4ee5\u6355\u6349\u5230\u66f4\u591a\u7684\u7ec6\u8282\u4fe1\u606f\uff0c\u80fd\u5728\u98ce\u683c\u8fc1\u79fb\u4e2d\u8868\u73b0\u66f4\u597d\uff0c\u56e0\u4e3a\u5728\u8fd9\u4e9b\u4efb\u52a1\u4e2d\u7ec6\u8282\u5f88\u91cd\u8981\u3002\u7f3a\u70b9\u662f\u53ef\u80fd\u4f1a\u8fc7\u5ea6\u5f3a\u8c03\u7ec6\u8282\u4fe1\u606f\uff0c\u5ffd\u7565\u4e86\u66f4\u5b8f\u89c2\u7684\u4fe1\u606f\u3002\u6b64\u5916instance norm\u7684\u8ba1\u7b97\u6210\u672c\u76f8\u6bd4batch norm\u548clayer norm\u4e5f\u66f4\u9ad8\u3002
Group norm: \u628a\u6bcf\u53e5\u8bdd\u7684\u6bcf\u51e0\u4e2a\u5b57\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002group norm\u662fbatch norm\u548cinstance norm\u7684\u6298\u4e2d\u65b9\u6848\uff0c\u5728\u4e00\u4e2a\u5b50\u96c6\uff08\u5373\u7ec4\uff09\u4e0a\u8fdb\u884c\u5f52\u4e00\u5316\u3002\u8fd9\u4f7f\u5f97group norm\u65e2\u53ef\u4ee5\u6355\u6349\u5230batch\u7684\u7edf\u8ba1\u7279\u6027\uff0c\u53c8\u53ef\u4ee5\u6355\u6349\u5230\u6837\u672c\u7684\u7ec6\u8282\u4fe1\u606f\u3002\u6b64\u5916\uff0cgroup norm\u5bf9batch\u5927\u5c0f\u4e5f\u4e0d\u654f\u611f\u3002\u7f3a\u70b9\u662fgroup norm\u7684\u6027\u80fd\u53d6\u51b3\u4e8e\u7ec4\u7684\u5927\u5c0f\uff0c\u9700\u8981\u901a\u8fc7\u5b9e\u9a8c\u786e\u5b9a\u6700\u4f18\u7ec4\u7684\u5927\u5c0f\u3002\u6b64\u5916group norm\u7684\u8ba1\u7b97\u6210\u672c\u4e5f\u6bd4batch norm\u548clayer norm\u66f4\u9ad8\u3002
Gradient Clipping RNN\u53ef\u80fd\u9047\u5230\u68af\u5ea6\u7206\u70b8\u95ee\u9898\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5982\u679c\u68af\u5ea6\u53d8\u5f97\u5f88\u5927\uff0c\u6211\u4eec\u5c06\u68af\u5ea6\u653e\u7f29\u4f7f\u5176\u53d8\u5c0f\u3002 \u7b97\u6cd5\u662f\uff1a\u5f53\u68af\u5ea6\u5927\u4e8e\u4e00\u4e2a\u5e38\u6570c\u7684\u65f6\u5019\uff0c\u6267\u884c \\(g\\leftarrow c\\times g/||g||\\)\u3002
\u4e3a\u4ec0\u4e48\u4f7f\u7528Dropout \u5982\u679c\u53c2\u6570\u592a\u591a\u800c\u8bad\u7ec3\u6837\u672c\u8fc7\u5c11\uff0c\u5bb9\u6613\u51fa\u73b0\u8fc7\u62df\u5408\u3002\u5177\u4f53\u8868\u73b0\u4e3a\uff1a\u5728dev set\u4e0aloss\u5f88\u5c0f\uff0c\u5728test set\u4e0aloss\u5f88\u5927\u3002 \u8fc7\u53bb\u4f1a\u9009\u62e9\u6a21\u578b\u96c6\u6210\uff0c\u8bad\u7ec3\u591a\u4e2a\u6a21\u578b\u8fdb\u884c\u7ec4\u5408\u3002Dropout\u80fd\u6bd4\u8f83\u6709\u6548\u7f13\u89e3\u8fc7\u62df\u5408\u3002\u7531Hinton\u57282012\u5e74\u63d0\u51fa\uff0c\u5e76\u5e94\u7528\u4e8eAlexNet\u3002 Dropout\u7684\u539f\u7406\u662f\u5728\u524d\u5411\u4f20\u64ad\u7684\u65f6\u5019\uff0c\u8ba9\u67d0\u4e2a\u795e\u7ecf\u5143\u7684\u6fc0\u6d3b\u503c\u4ee5\u4e00\u5b9a\u6982\u7387p\u505c\u6b62\u5de5\u4f5c\uff0c\u53ef\u4ee5\u4f7f\u6a21\u578b\u6cdb\u5316\u80fd\u529b\u66f4\u5f3a\uff0c\u56e0\u4e3a\u4e0d\u4f1a\u592a\u4f9d\u8d56\u67d0\u4e9b\u5c40\u90e8\u7279\u5f81\u3002 \u5de5\u4f5c\u6d41\u7a0b\uff1a 1\uff09\u968f\u673a\uff08\u4e34\u65f6\uff09\u5220\u9664\u4e00\u534a\u7684\u9690\u85cf\u795e\u7ecf\u5143\uff0c\u4fdd\u7559\u8f93\u5165\u8f93\u51fa\u795e\u7ecf\u5143\u4e0d\u53d8\uff0c\u88ab\u5220\u9664\u7684\u4fdd\u7559\u53c2\u6570\u4e0d\u53d8\u3002 2\uff09\u5c06\u8f93\u5165\u524d\u5411\u4f20\u64ad\u540e\u540e\u5411\u4f20\u64ad\uff0c\u53ea\u66f4\u65b0\u5269\u4e0b\u795e\u7ecf\u5143\u4e0a\u7684\u53c2\u6570\u3002 3\uff09\u6062\u590d\u88ab\u5220\u6389\u7684\u795e\u7ecf\u5143\uff08\u6b64\u65f6\u88ab\u5220\u9664\u7684\u795e\u7ecf\u5143\u4fdd\u6301\u539f\u6837\uff0c\u800c\u6ca1\u6709\u88ab\u5220\u9664\u7684\u795e\u7ecf\u5143\u5df2\u7ecf\u66f4\u65b0\uff09\u3002 4\uff09\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\u3002
\u4e0b\u9762\u7684\u4e00\u7bc7\u4e00\u7bc7\u6574\u7406 - Microstrong\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2dDropout\u539f\u7406\u89e3\u6790 - \u795e\u7ecf\u7f51\u7edcDropout\u5c42\u4e2d\u4e3a\u4ec0\u4e48dropout\u540e\u8fd8\u9700\u8981\u8fdb\u884crescale\uff1f - bingo\u9171\uff1aL1\u6b63\u5219\u5316\u4e0eL2\u6b63\u5219\u5316 - \u97e6\u4f1f\uff1a\u4ece\u53cd\u5411\u4f20\u64ad\u63a8\u5bfc\u5230\u68af\u5ea6\u6d88\u5931and\u7206\u70b8\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848\uff08\u4eceDNN\u5230RNN\uff0c\u5185\u9644\u8be6\u7ec6\u53cd\u5411\u4f20\u64ad\u516c\u5f0f\u63a8\u5bfc\uff09 - Will\uff1a\u795e\u7ecf\u7f51\u7edc\u8bad\u7ec3\u4e2d\u7684\u68af\u5ea6\u6d88\u5931\u4e0e\u68af\u5ea6\u7206\u70b8 - LSTM\u5982\u4f55\u6765\u907f\u514d\u68af\u5ea6\u5f25\u6563\u548c\u68af\u5ea6\u7206\u70b8\uff1f - LSTM\u5982\u4f55\u6765\u907f\u514d\u68af\u5ea6\u5f25\u6563\u548c\u68af\u5ea6\u7206\u70b8\uff1f
"},{"location":"DL/NLPTech/ml_cheatsheet/#_1","title":"\u56db\u3001\u673a\u5668\u5b66\u4e60","text":"\u9700\u8981\u5728\u56db\u672c\u683c\u5f0f\u4e0d\u4e00\u6837\u7684\u8bcd\u5178\u4e2d\u63d0\u53d6\u51fa\u76f8\u540c\u683c\u5f0f\u7684\u8bcd\u6e90\u4fe1\u606f\uff0c\u8bcd\u6e90\u4e00\u5171\u67099\u5927\u7c7b+\u4e00\u79cd\"Other\"\uff0c\u6587\u672c\u4e2d\u6709\u6570\u4e2a\u8bcd\u6e90\u4fe1\u606f\uff0c\u9700\u8981\u627e\u5230\u6700\u521d\u7684\u90a3\u4e2a\u8bcd\u6e90\u4fe1\u606f\uff0c\u5f52\u52309\u5927\u7c7b\u4e2d\u5e76\u8bb0\u5f55\u4e0b\u6765\u5177\u4f53\u662f\u54ea\u4e00\u7c7b\u3002 \u9700\u8981\u7684\u683c\u5f0f
[{\n\"word\": \"\",\n\"etymology\": [\n{\n\"origin\": \"\",\n\"source\": \"\",\n\"excerpt\": \"\"\n},\n{\n\"origin\": \"\",\n\"source\": \"\",\n\"excerpt\": \"\"\n}\n]\n}]\n
"},{"location":"DL/NLPTech/rule_text/#_2","title":"\u65b9\u6cd5","text":"\"An ultimate origin of a word is the language where a word comes from at the very beginning, or the language where it appears at the earliest time. For the given word %s, please find its ultimate origin of this word from the following passage: %s. You should only answer one word from Anglo, Arabic, Asian, Celtic, English, French, Germanic, Greek, Latin, Spanish, or Other, without outputing anything else. If the origin not provided, just output Other. Origin: %s\" % (\"a\", \"prefix meaning \\\"not,\\\" from Latin. a-, short for ab \\\"away from\\\" (cf. avert), or its cognate, Greek. a-, short for apo \\\"away from, from,\\\" both cognate with Skt. apa \\\"away from,\\\" Goth. af, Old.English. of. \", \"Latin\")\n
\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\uff0c\u4e3a\u4e86\u9632\u6b62ChatGPT\u5c06English\u7406\u89e3\u6210Other\u800c\u975eAnglo\uff0c\u7279\u610f\u5c06English\u6dfb\u52a0\u5728\u4e86\u5907\u9009\u9879\u4e2d\uff0c\u4e4b\u540e\u518d\u5bf9\u8fd4\u56de\u7684English\u7c7b\u522b\u505a\u4e00\u4e2a\u89c4\u5219\u5904\u7406\u3002\u9700\u8981\u5c06\u4e00\u4e2a\u6587\u672c\u5e93\u4e2d\u7684\u6587\u672c\u5206\u8bcd\u540e\u8bcd\u5f62\u8fd8\u539f 1. nltk \u4f18\u70b9\uff1a\u8c03\u7528\u7b80\u5355\uff0c\u5feb \u7f3a\u70b9\uff1a\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a\uff0c\u5f80\u5f80\u9700\u8981\u624b\u52a8\u4e0b\u8f7d\u540e\u653e\u5728\u672c\u5730\u7684nltk\u6587\u4ef6\u5939\u4e2d\uff0c\u51c6\u786e\u7387\u4f4e\u4e00\u4e9b 2. spaCy \u4f18\u70b9\uff1a\u51c6\u786e\u7387\u66f4\u9ad8 \u7f3a\u70b9\uff1a\u8c03\u7528\u6162\uff0c\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a 3. stanza \u4f18\u70b9\uff1a\u51c6\u786e\u7387\u66f4\u9ad8 \u7f3a\u70b9\uff1a\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a
\u4e09\u4e2a\u5305\u7684\u63a8\u8350\u7a0b\u5ea6\u6392\u5e8f stanza = spaCy > nltk
"},{"location":"DL/NLPTech/transformer_code/","title":"Notes on Transformer Code","text":""},{"location":"DL/NLPTech/transformer_code/#introduction","title":"Introduction","text":"This note only focuses on the classes and eliminates all other packages or data processing lines.
To implement a Transformer model, the following classes need to be implemented. - embeddings: positional encoding, token embedding, transformer embedding - layers: layer norm, multi-head attention, position-wise feed forward, scale dot product attention - blocks: encoder-layer, decoder-layer - model: encoder, decoder, Transformer
"},{"location":"DL/NLPTech/transformer_code/#utils","title":"Utils","text":"import torch\nfrom torch import nn\n
"},{"location":"DL/NLPTech/transformer_code/#positional-embedding","title":"Positional embedding","text":"class PositionalEncoding(nn.Module):\n\"\"\"\n compute sinusoid encoding.\n \"\"\"\ndef __init__(self, d_model, max_len, device):\n\"\"\"\n constructor of sinusoid encoding class\n :param d_model: dimension of model\n :param max_len: max sequence length\n :param device: hardware device setting\n \"\"\"\nsuper(PositionalEncoding, self).__init__()\n# same size with input matrix (for adding with input matrix)\nself.encoding = torch.zeros(max_len, d_model, device=device)\nself.encoding.requires_grad = False # we don't need to compute gradient\npos = torch.arange(0, max_len, device=device)\npos = pos.float().unsqueeze(dim=1)\n# 1D => 2D unsqueeze to represent word's position\n_2i = torch.arange(0, d_model, step=2, device=device).float()\n# 'i' means index of d_model (e.g. embedding size = 50, 'i' = [0,50])\n# \"step=2\" means 'i' multiplied with two (same with 2 * i)\nself.encoding[:, 0::2] = torch.sin(pos / (10000 ** (_2i / d_model)))\nself.encoding[:, 1::2] = torch.cos(pos / (10000 ** (_2i / d_model)))\n# compute positional encoding to consider positional information of words\ndef forward(self, x):\n# self.encoding\n# [max_len = 512, d_model = 512]\nbatch_size, seq_len = x.size()\n# [batch_size = 128, seq_len = 30]\nreturn self.encoding[:seq_len, :]\n# [seq_len = 30, d_model = 512]\n# it will add with tok_emb : [128, 30, 512]\n
"},{"location":"DL/NLPTech/transformer_code/#token-embedding","title":"Token Embedding","text":"class TokenEmbedding(nn.Embedding):\n\"\"\"\n Token Embedding using torch.nn\n they will dense representation of word using weighted matrix\n \"\"\"\ndef __init__(self, vocab_size, d_model):\n\"\"\"\n class for token embedding that included positional information\n :param vocab_size: size of vocabulary\n :param d_model: dimensions of model\n \"\"\"\nsuper(TokenEmbedding, self).__init__(vocab_size, d_model, padding_idx=1)\n
"},{"location":"DL/NLPTech/transformer_code/#transformer-embedding","title":"Transformer Embedding","text":"Transformer adopts an embedding which is a summation of the token embedding and the positional embedding.
class TransformerEmbedding(nn.Module):\n\"\"\"\n token embedding + positional encoding (sinusoid)\n positional encoding can give positional information to network\n \"\"\"\ndef __init__(self, vocab_size, d_model, max_len, drop_prob, device):\n\"\"\"\n class for word embedding that included positional information\n :param vocab_size: size of vocabulary\n :param d_model: dimensions of model\n \"\"\"\nsuper(TransformerEmbedding, self).__init__()\nself.tok_emb = TokenEmbedding(vocab_size, d_model)\nself.pos_emb = PositionalEncoding(d_model, max_len, device)\nself.drop_out = nn.Dropout(p=drop_prob)\ndef forward(self, x):\ntok_emb = self.tok_emb(x)\npos_emb = self.pos_emb(x)\nreturn self.drop_out(tok_emb + pos_emb)\n
"},{"location":"DL/NLPTech/transformer_code/#scale-dot-product-attention","title":"Scale dot product attention","text":"class ScaleDotProductAttention(nn.Module):\n\"\"\"\n compute scale dot product attention\n Query : given sentence that we focused on (decoder)\n Key : every sentence to check relationship with Qeury(encoder)\n Value : every sentence same with Key (encoder)\n \"\"\"\ndef __init__(self):\nsuper(ScaleDotProductAttention, self).__init__()\nself.softmax = nn.Softmax(dim=-1)\ndef forward(self, q, k, v, mask=None, e=1e-12):\n# input is 4 dimension tensor\n# [batch_size, head, length, d_tensor]\nbatch_size, head, length, d_tensor = k.size()\n# 1. dot product Query with Key^T to compute similarity\nk_t = k.transpose(2, 3) # transpose\nscore = (q @ k_t) / math.sqrt(d_tensor) # scaled dot product\n# 2. apply masking (opt)\nif mask is not None:\nscore = score.masked_fill(mask == 0, -10000)\n# 3. pass them softmax to make [0, 1] range\nscore = self.softmax(score)\n# 4. multiply with Value\nv = score @ v\nreturn v, score\n
"},{"location":"DL/NLPTech/transformer_code/#multi-head-attention","title":"Multi-head Attention","text":"A multi-head attention is a self-attention running in parallel. The multi-head attention module output an attention output and an attention weight matrix with the scaled-dot product module.
class MultiHeadAttention(nn.Module):\n\"\"\"\n q, k, v: with dimension of d_model to d_model. Each is a weight matrix.\n \"\"\"\ndef __init__(self, d_model, n_head):\nsuper(MultiHeadAttention, self).__init__()\nself.n_head = n_head\nself.attention = ScaleDotProductAttention()\nself.w_q = nn.Linear(d_model, d_model)\nself.w_k = nn.Linear(d_model, d_model)\nself.w_v = nn.Linear(d_model, d_model)\nself.w_concat = nn.Linear(d_model, d_model)\ndef forward(self, q, k, v, mask=None):\n\"\"\"\n query = [batch size, query len, hid dim]\n key = [batch size, key len, hid dim]\n value = [batch size, value len, hid dim]\n \"\"\"\n# 1. dot product with weight matrices\nq, k, v = self.w_q(q), self.w_k(k), self.w_v(v)\n# 2. split tensor by number of heads\nq, k, v = self.split(q), self.split(k), self.split(v)\n# 3. do scale dot product to compute similarity\nout, attention = self.attention(q, k, v, mask=mask)\n# 4. concat and pass to linear layer\nout = self.concat(out)\nout = self.w_concat(out)\nreturn out\ndef split(self, tensor):\n\"\"\"\n split tensor by number of head\n :param tensor: [batch_size, length, d_model]\n :return: [batch_size, head, length, d_tensor]\n \"\"\"\nbatch_size, length, d_model = tensor.size()\n# head dimension = hidden dimension // number of heads\nd_tensor = d_model // self.n_head\ntensor = tensor.view(batch_size, length, self.n_head, d_tensor).transpose(1, 2)\n# it is similar with group convolution (split by number of heads)\nreturn tensor\ndef concat(self, tensor):\n\"\"\"\n inverse function of self.split(tensor : torch.Tensor)\n :param tensor: [batch_size, head, length, d_tensor]\n :return: [batch_size, length, d_model]\n \"\"\"\nbatch_size, head, length, d_tensor = tensor.size()\nd_model = head * d_tensor\ntensor = tensor.transpose(1, 2).contiguous().view(batch_size, length, d_model)\nreturn tensor\n
"},{"location":"DL/NLPTech/transformer_code/#position-wise-feed-forward-layer","title":"Position-wise Feed Forward Layer","text":"Another main block inside the encoder is the positionwise ffd. The input is transformed from hid_dim to pf_dim, where pf_dim is usually much larger than the hid_dim. The original transformer has a hid_dim of 512 while a pf_dim of 2048. The purpose of this block is not explained in the Transformer paper.
class PositionwiseFeedForward(nn.Module):\ndef __init__(self, d_model, hidden, drop_prob=0.1):\nsuper(PositionwiseFeedForward, self).__init__()\nself.linear1 = nn.Linear(d_model, hidden)\nself.linear2 = nn.Linear(hidden, d_model)\nself.relu = nn.ReLU()\nself.dropout = nn.Dropout(p=drop_prob)\ndef forward(self, x):\nx = self.linear1(x)\nx = self.relu(x)\nx = self.dropout(x)\nx = self.linear2(x)\nreturn x\n
"},{"location":"DL/NLPTech/transformer_code/#layer-norm","title":"Layer Norm","text":"class LayerNorm(nn.Module):\ndef __init__(self, d_model, eps=1e-12):\nsuper(LayerNorm, self).__init__()\nself.gamma = nn.Parameter(torch.ones(d_model))\nself.beta = nn.Parameter(torch.zeros(d_model))\nself.eps = eps\ndef forward(self, x):\nmean = x.mean(-1, keepdim=True)\nvar = x.var(-1, unbiased=False, keepdim=True)\n# '-1' means last dimension. \nout = (x - mean) / torch.sqrt(var + self.eps)\nout = self.gamma * out + self.beta\nreturn out\n
"},{"location":"DL/NLPTech/transformer_code/#encoder","title":"Encoder","text":"First we build an encoder layer.
class EncoderLayer(nn.Module):\ndef __init__(self, d_model, ffn_hidden, n_head, drop_prob):\nsuper(EncoderLayer, self).__init__()\nself.attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm1 = LayerNorm(d_model=d_model)\nself.dropout1 = nn.Dropout(p=drop_prob)\nself.ffn = PositionwiseFeedForward(d_model=d_model, hidden=ffn_hidden, drop_prob=drop_prob)\nself.norm2 = LayerNorm(d_model=d_model)\nself.dropout2 = nn.Dropout(p=drop_prob)\ndef forward(self, x, src_mask):\n# 1. compute self attention\n_x = x\nx = self.attention(q=x, k=x, v=x, mask=src_mask)\n# 2. add and norm\nx = self.dropout1(x)\nx = self.norm1(x + _x)\n# 3. positionwise feed forward network\n_x = x\nx = self.ffn(x)\n# 4. add and norm\nx = self.dropout2(x)\nx = self.norm2(x + _x)\nreturn x\n
And then the whole encoder. class Encoder(nn.Module):\n\"\"\"\n enc_voc_size: dictionary size\n max_len: max input length\n n_layers: defines #encoder_layers to stack in the encoder\n \"\"\"\ndef __init__(self, enc_voc_size, max_len, d_model, ffn_hidden, n_head, n_layers, drop_prob, device):\nsuper().__init__()\nself.emb = TransformerEmbedding(d_model = d_model, max_len = max_len, \nvoacb_size = enc_voc_size, drop_prob = drop_prob, device = device)\n# a stacked encoder\nself.layers = nn.ModuleList([EncoderLayer(d_model = d_model, ffn_hidden = ffn_hidden, \nn_head = n_head, drop_prob = drop_prob)\nfor _ in range(n_layers)])\ndef forward(self, x, src_mask): # src_mask: during Transformer's training, a forward mask\nx = self.emb(x)\nfor layer in self.layers:\nx = layer(x, src_mask)\nreturn x\n
"},{"location":"DL/NLPTech/transformer_code/#decoder","title":"Decoder","text":"First we build a decoder layer.
class DecoderLayer(nn.Module):\ndef __init__(self, d_model, ffn_hidden, n_head, drop_prob):\nsuper(DecoderLayer, self).__init__()\nself.self_attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm1 = LayerNorm(d_model=d_model)\nself.dropout1 = nn.Dropout(p=drop_prob)\nself.enc_dec_attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm2 = LayerNorm(d_model=d_model)\nself.dropout2 = nn.Dropout(p=drop_prob)\nself.ffn = PositionwiseFeedForward(d_model=d_model, hidden=ffn_hidden, drop_prob=drop_prob)\nself.norm3 = LayerNorm(d_model=d_model)\nself.dropout3 = nn.Dropout(p=drop_prob)\ndef forward(self, dec, enc, trg_mask, src_mask):\n# 1. compute self attention\n_x = dec # ideal target\nx = self.self_attention(q=dec, k=dec, v=dec, mask=trg_mask) # predicted target\n# 2. add and norm\nx = self.dropout1(x)\nx = self.norm1(x + _x)\nif enc is not None:\n# 3. compute encoder - decoder attention\n_x = x\nx = self.enc_dec_attention(q=x, k=enc, v=enc, mask=src_mask)\n# 4. add and norm\nx = self.dropout2(x)\nx = self.norm2(x + _x)\n# 5. positionwise feed forward network\n_x = x\nx = self.ffn(x)\n# 6. add and norm\nx = self.dropout3(x)\nx = self.norm3(x + _x)\nreturn x\n
And then the whole decoder. class Decoder(nn.Module):\ndef __init__(self, dec_voc_size, max_len, d_model, ffn_hidden, n_head, n_layers, drop_prob, device):\nsuper().__init__()\nself.emb = TransformerEmbedding(d_model = d_model, drop_prob = drop_prob, \nmax_len = max_len, vocab_size = dec_voc_size, device = devoce)\n# a stacked decoder layer\nself.layers = nn.ModuleList([DecoderLayer(d_model = d_model, ffn_hidden = ffn_hidden, \nn_head = n_head, drop_prob = drop_prob)\nfor _ in range(n_layers)])\nself.linear = nn.Linear(d_model, dec_voc_size)\n\"\"\"\n trg = [batch size, trg len]\n enc_src = [batchsize, src len, hid dim]\n trg_mask = [batch size, 1, trg len, trg len]\n src_mask = [batch size, 1, 1, src len] \n \"\"\"\ndef forward(self, trg, enc_src, trg_mask, src_mask):\ntrg = self.emb(trg)\nfor layer in self.layers:\ntrg = layer(trg, enc_src, trg_mask, src_mask)\n# pass to LM head\noutput = self.linear(trg)\nreturn output\n
"},{"location":"DL/NLPTech/transformer_code/#transformer-model","title":"Transformer Model","text":"The model use forward's src and trg to receive the input and output during both training and testing procedures. During training, the trgs are as references of calculating training loss, while during testing, the testing loss. In the DecoderLayer class, the ideal target and predicted target are compared.
class Transformer(nn.Module):\n\"\"\"\n src_pad_idx: A matrix indicating <pad> positions in the input. <pad>s are not paid attention\n trg_pad_idx: A matrix indicating <pad> positions in the output. <pad>s are not paid attention\n trg_sos_idx: A matrix indicating <sos> positions in the output. Sentence initial.\n enc_voc_size: input encoding size\n dec_voc_size: output encoding size\n d_model: Usually an emphirical value of \\sqrt[4]{#classes}. Originally 512\n n_head: number of heads. Originally 8.\n max_len: limit on the input length\n ffn_hidden: number of hidden layers in the ffn\n n_layers: #layers in stacked encoder and decoder. Originally 6.\n drop_prob: drop out probability\n device: cpu or gpu\n \"\"\"\ndef __init__(self, src_pad_idx, trg_pad_idx, trg_sos_idx, enc_voc_size, dec_voc_size, d_model, n_head, max_len, ffn_hidden, n_layers, drop_prob, device):\nsuper().__init__()\nself.src_pad_idx = src_pad_idx\nself.trg_pad_idx = trg_pad_idx\nself.trg_sos_idx = trg_sos_idx\nself.device = device\nself.encoder = Encoder(d_model=d_model,\nn_head=n_head,\nmax_len=max_len,\nffn_hidden=ffn_hidden,\nenc_voc_size=enc_voc_size,\ndrop_prob=drop_prob,\nn_layers=n_layers,\ndevice=device)\nself.decoder = Decoder(d_model=d_model,\nn_head=n_head,\nmax_len=max_len,\nffn_hidden=ffn_hidden,\ndec_voc_size=dec_voc_size,\ndrop_prob=drop_prob,\nn_layers=n_layers,\ndevice=device)\ndef forward(self, src, trg):\nsrc_mask = self.make_src_mask(src)\ntrg_mask = self.make_trg_mask(trg)\nenc_src = self.encoder(src, src_mask)\noutput = self.decoder(trg, enc_src, trg_mask, src_mask)\nreturn output\ndef make_src_mask(self, src):\nsrc_mask = (src != self.src_pad_idx).unsqueeze(1).unsqueeze(2)\nreturn src_mask\ndef make_trg_mask(self, trg):\ntrg_pad_mask = (trg != self.trg_pad_idx).unsqueeze(1).unsqueeze(3)\ntrg_len = trg.shape[1]\ntrg_sub_mask = torch.tril(torch.ones(trg_len, trg_len)).type(torch.ByteTensor).to(self.device)\ntrg_mask = trg_pad_mask & trg_sub_mask\nreturn trg_mask\n
Let's finally see the default configs.
# GPU device setting\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n# model parameter setting\nbatch_size = 128\nmax_len = 256\nd_model = 512\nn_layers = 6\nn_heads = 8\nffn_hidden = 2048\ndrop_prob = 0.1\n# optimizer parameter setting\ninit_lr = 1e-5\nfactor = 0.9\nadam_eps = 5e-9\npatience = 10\nwarmup = 100\nepoch = 1000\nclip = 1.0\nweight_decay = 5e-4\ninf = float('inf')\n
"},{"location":"DL/NLPTech/transformer_code/#references","title":"References","text":"Vaswani et al. Attention is all you need. 2017 hyunwoongko/transformer: PyTorch Implementation of \"Attention Is All You Need\" (github.com) 6 - Attention is All You Need.ipynb - Colaboratory (google.com)
"},{"location":"DL/NLPTheory/","title":"\u7d22\u5f15","text":"\u8fd9\u4e2a\u7d22\u5f15\u6ca1\u5199\u5b8c
\u800c\u4e14\u6211\u4e5f\u4e0d\u8bb0\u5f97\u4e3a\u4ec0\u4e48\u4e0b\u9762\u653e\u4e86\u8fd9\u5f20\u56fe\u4e86
"},{"location":"DL/NLPTheory/autoregressive/","title":"Autogressive Decoder","text":"TODO
This note collects papers that demonstrates the shortcomings of autoregressive decoders. Two main common concerns about the autoregressive decoders are that they are lacking the generalizability and the efficiency with respect to the amount of training data, due to the limitation of its structure.
"},{"location":"DL/NLPTheory/autoregressive/#limitation-in-generalizability","title":"Limitation in generalizability","text":"Information theory based: compositionality climbing towards NLU: only learning the surface structure of language
In this paper, we
"},{"location":"DL/NLPTheory/autoregressive/#towards-revealing-the-mystery-behind-chain-of-thought-a-theoretical-perspective-2023","title":"Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective (2023)","text":"This paper points out the reason why the CoT success in prompting LLMs. \u589e\u52a0\u6a21\u578b\u7684\u6709\u6548\u6df1\u5ea6
"},{"location":"DL/NLPTheory/autoregressive/#deep-encoder-shallow-decoder-reevaluating-the-speed-quality-tradeoff-in-machine-translation","title":"Deep Encoder, Shallow Decoder: Reevaluating the Speed-Quality Tradeoff in Machine Translation","text":"In section Deep Encoder, Shallow Decoder, this paper discusses the
(Edunov et al., 2018; Pinnis et al., 2018; Ng et al., 2019).
"},{"location":"DL/NLPTheory/autoregressive/#limitation-in-error-accumulation","title":"Limitation in error accumulation","text":"GSM8k uses a verifier to correct the mistakes in reasoning paths, which is a worthy attempt. However, more efficient verification and correction in the early reasoning stage should also be explored. GSM8k and scaling relationship also indicates the log linear-hood has not been reached by the autoregressive decoders.
"},{"location":"DL/NLPTheory/cot/","title":"Chain of Thought Prompting","text":""},{"location":"DL/NLPTheory/cot/#_1","title":"\u4efb\u52a1\u76ee\u6807","text":"\u672c\u5b9e\u9a8c\u65e8\u5728\u6d4b\u8bc4ChatGPT\u5728\u9605\u8bfb\u7406\u89e3\u4efb\u52a1\uff08Multiple-choice Comprehension, MRC\uff09\u4e0a\u7684\u8868\u73b0\uff0c\u5e76\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6316\u6398\u63d0\u793a\u8bcd\uff0c\u901a\u8fc7\u4e0d\u6539\u53d8\u6570\u636e\u96c6\u548c\u6a21\u578b\u53ea\u6539\u53d8\u63d0\u793a\u8bcd\u7684\u65b9\u6cd5\uff0c\u63d0\u9ad8\u5927\u6a21\u578b\u5728MRC\u4e0a\u7684\u8868\u73b0\u3002
"},{"location":"DL/NLPTheory/cot/#_2","title":"\u5b9e\u9a8c\u8bbe\u8ba1","text":"\u4e3a\u8282\u7ea6\u65f6\u95f4\u548c\u91d1\u94b1\u6210\u672c\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5b9e\u9a8c\uff0c\u6211\u4eec\u4ec5\u6d4b\u8bd520\u4e2a\u95ee\u9898
"},{"location":"DL/NLPTheory/cot/#_3","title":"\u6570\u636e\u96c6","text":"AQuA\u6570\u636e\u96c6\u9898\u63d0\u4f9b\u4e86100,000\u9053\u7528\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u7684\u6570\u5b66\u9898\u3002 https://github.com/deepmind/AQuA
"},{"location":"DL/NLPTheory/cot/#benchmark-zero-shot-prompting","title":"Benchmark: Zero-shot Prompting","text":"\u6700\u7b80\u5355\u7684MRC\u95ee\u9898\uff0c\u53ea\u8f93\u5165question\u548coptions The dataset consists of about 100,000 algebraic word problems with natural language rationales. Each problem is a json object consisting of four parts:
question
\u00a0- A natural language definition of the problem to solveoptions
\u00a0- 5 possible options (A, B, C, D and E), among which one is correctrationale
\u00a0- A natural language description of the solution to the problemcorrect
\u00a0- The correct option{\n\"question\": \"A grocery sells a bag of ice for $1.25, and makes 20% profit. If it sells 500 bags of ice, how much total profit does it make?\",\n\"options\": [\"A)125\", \"B)150\", \"C)225\", \"D)250\", \"E)275\"],\n\"rationale\": \"Profit per bag = 1.25 * 0.20 = 0.25\\nTotal profit = 500 * 0.25 = 125\\nAnswer is A.\",\n\"correct\": \"A\"\n}\n
"},{"location":"DL/NLPTheory/cot/#self-consistency","title":"Self-Consistency","text":"# \u5c06\u95ee\u9898\u6309\u53e5\u5b50\u5206\u5f00\uff0c\u5e76\u968f\u673a\u6253\u4e71\u53e5\u5b50\nquestion_sentences = question.split('. ')\nquestion = '. '.join(shuffled(question_sentences))\n# \u5206\u522b\u5c06\u95ee\u9898\u8f93\u5165\u7ed9\u591a\u4e2aChatGPT\nfor i in range(GPT_number):\n answers.append(query(ChatGPT_i, question))\n# \u5c06\u56de\u7b54\u66f4\u591a\u7684\u7b54\u6848vote\u4e3a\u6b63\u786e\u7b54\u6848\nfinal_answer = top_one(answers)\n
\u5bf9\u4e8e\u6bcf\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u5148\u5c06question\u968f\u673a\u6253\u4e71\uff0c\u7136\u540e\u8f93\u5165\u7ed9\u4e09\u4e2agpt\uff08\u4e0d\u76f8\u90bb\u7684\u4e09\u8f6e\uff09\uff0c\u8ba9\u5b83\u4eecvote
"},{"location":"DL/NLPTheory/cot/#multi-step-verifier","title":"multi-step verifier","text":"\u8fd9\u4e2a\u8981\u63a5\u4e00\u4e2averifier model
# \u5206\u522b\u5c06\u95ee\u9898\u8f93\u5165\u7ed9\u591a\u4e2aChatGPT\uff0c\u63a2\u7d22\u5c3d\u53ef\u80fd\u591a\u7684\u63a8\u7406\u8def\u5f84\nfor i in range(GPT_number):\n answers.append(query(ChatGPT_i, question))\n\n# \u4f7f\u7528\u4e00\u4e2afine-tuned\u7684Verifier\uff0c\u6839\u636e\u6570\u636e\u96c6\u6807\u7b7e\u4e3aanswer\u7684\u6bcf\u4e00\u6b65\u6253\u5206\nscores = []\nfor answer in answers:\n score = 0\n for step in answer:\n score += Verifier(step, gold_label)\n scores.append(score)\n\n# \u5c06score\u66f4\u9ad8\u7684\u7b54\u6848vote\u4e3a\u6b63\u786e\u7b54\u6848\nfinal_answer = top_one(scores->answer)\n
\u8fd9\u7bc7\u7684\u6570\u636e\u96c6HotpotQA\uff0c\u8be5\u6570\u636e\u96c6\u5185\u90e8\u63d0\u4f9b\u95ee\u9898\u3001\u56de\u7b54\uff0c\u548c\u76f8\u5e94\u7684\u6587\u7ae0context\u3002
"},{"location":"DL/NLPTheory/cot/#chain-of-thought-prompting-elicits-reasoning-in-large-language-models","title":"Chain-of-Thought Prompting Elicits Reasoning in Large Language Models","text":"\u6dfb\u52a0lets think step by step + \u5e26cot\u76841-shot
prompt = [I, t, q] -> y\nI: instruction\nt: example\nq: question\ny: answer\n
example:
There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n
applicable to
two assumptions
IRCoT mian components
main components
template original paragraph (incorrect)
The first number is 0, the second number is 1, therefore, the third number is 0+1=1.\nThe fourth number is 1+1=2. The fifth number is 1+2=3. The sixth number is 2+3=5.\n(skip..)\nThe 50th number is 32,432,268,459\n
PoT (correct)
length_of_fibonacci_sequence = 50\nfibonacci_sequence = np.zeros(length_of_)\nfibonacci_sequence[0] = 0\nfibonacci_sequence[1] = 1\nfor i in range(3, length_of_fibonacci_sequence):\nfibonacci_sequnce[i] = fibonacci_sequence[i-1] +\nfibonacci_sequence[i-2]\nans = fibonacci_sequence[-1]\n
"},{"location":"DL/NLPTheory/cot/#cos-chain-of-symbol-prompting","title":"CoS (Chain of Symbol Prompting)","text":"template shared model input
There are a set of bricks. The yellow brick C is on top of the brick E . The yellow brick D is on top of the brick A . The yellow brick E is on top of the brick D . The white brick A is on top of the brick B . For the brick B, the color is white. Now we have to get a specific brick. The bricks must now be grabbed from top to bottom, and if the lower brick is to be grabbed, the upper brick must be removed first. How to get brick D?\n
cot prompting (wrong)
The bricks from bottom to top is B, A, D, E, C 1. Remove brick A from the top of brick B. 2. Remove brick E from the top of brick D. 3. Now brick D is the topmost yellow brick and can be grabbed.\n
cos prompting (correct)
B/A/D/E/C C/E E/D D\n
"},{"location":"DL/NLPTheory/embodied_ai/","title":"Embodied AI","text":"TODO
WooooDyy/LLM-Agent-Paper-List: The paper list of the 86-page paper \"The Rise and Potential of Large Language Model Based Agents: A Survey\" by Zhiheng Xi et al. (github.com)
"},{"location":"DL/NLPTheory/embodied_ai/#1-the-birth-of-an-agent-construction-of-llm-based-agents","title":"1. The Birth of An Agent: Construction of LLM-based Agents","text":""},{"location":"DL/NLPTheory/embodied_ai/#11-brain-primarily-composed-of-an-llm","title":"1.1 Brain: Primarily Composed of An LLM","text":""},{"location":"DL/NLPTheory/embodied_ai/#111-natural-language-interaction","title":"1.1.1 Natural Language Interaction","text":""},{"location":"DL/NLPTheory/embodied_ai/#high-quality-generation","title":"High-quality generation","text":"[2023/05]\u00a0Self-Polish: Enhance Reasoning in Large Language Models via Problem Refinement. Zhiheng Xi (Fudan University) et al. arXiv.\u00a0[paper] [code]
[2023-03]\u00a0Large Language Models are Zero-Shot Reasoners. Takeshi Kojima (The University of Tokyo) et al. arXiv.\u00a0[paper][code]
[2023/03]\u00a0Self-Refine: Iterative Refinement with Self-Feedback. Aman Madaan (Carnegie Mellon University) et al. arXiv.\u00a0[paper] [code]
[2022/05]\u00a0Selection-Inference: Exploiting Large Language Models for Interpretable Logical Reasoning. Antonia Creswell (DeepMind) et al. arXiv.\u00a0[paper]
[2022/03]\u00a0Self-Consistency Improves Chain of Thought Reasoning in Language Models. Xuezhi Wang(Google Research) et al. arXiv.\u00a0[paper] [code]
[2022/01]\u00a0Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. Jason Wei (Google Research,) et al. arXiv.\u00a0[paper]
In web scenarios
In life scenarios
Disordered cooperation
Ordered cooperation
[2023/09]\u00a0Exploring Large Language Models for Communication Games: An Empirical Study on Werewolf. Yuzhuang Xu (Tsinghua University) et al. arXiv.\u00a0[paper]
[2023/08]\u00a0AgentVerse: Facilitating Multi-Agent Collaboration and Exploring Emergent Behaviors in Agents. Weize Chen (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation Framework. Qingyun Wu (Pennsylvania State University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0ChatEval: Towards Better LLM-based Evaluators through Multi-Agent Debate. Chi-Min Chan (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/07]\u00a0Communicative Agents for Software Development. Chen Qian (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/07]\u00a0RoCo: Dialectic Multi-Robot Collaboration with Large Language Models. Zhao Mandi, Shreeya Jain, Shuran Song (Columbia University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0ProAgent: Building Proactive Cooperative AI with Large Language Models. Ceyao Zhang (The Chinese University of Hong Kong, Shenzhen) et al. arXiv.\u00a0[paper] [code]
TODO
"},{"location":"DL/NLPTheory/explainable_nlp/#survey","title":"Survey","text":""},{"location":"DL/NLPTheory/explainable_nlp/#a-survey-of-the-state-of-explainable-ai-for-natural-language-processing","title":"A Survey of the State of Explainable AI for Natural Language Processing","text":"This survey thoroughly explains the state of explainable NLP. The Introduction discusses two distinguishing criteria for explanability models (1) whether the explanation is for each prediction individually or the model\u2019s prediction process as a whole, and (2) determining whether generating the explanation requires post-processing or not. In Categorization of Explanations, this paper categorizes the explanation models into local (provides information or justification for the model's prediction on a specific input) vs. global (provides similar justification by revealing how the model's predictive process works, independently of any particular input), and self-explaining (also directly interpretable, generates the explanation at the same time as the prediction, e.g. decision trees, rule-based models, and feature saliency models like attention models) vs. post-hoc (an additional operation is performed after the predictions are made). This section also states that the different categories of models can overlap. In section Aspects of Explanations, this paper introduces three types of explanation techniques: (1) explainability techniques (feature importance, surrogate model, example-driven, provenance-based, declarative induction), (2) operations to enable explainability (first-derivation saliency, layer-wise relevance propagation, and input perturbations, attention, LSTM gating signals, explainability-aware architecture design) and (3) visualization techniques (saliency, raw declarative representations, natural language explanation). The section Evaluation introduces several evaluating metrices.
"},{"location":"DL/NLPTheory/explainable_nlp/#opinion-papers","title":"Opinion Papers","text":""},{"location":"DL/NLPTheory/explainable_nlp/#climbing-towards-nlu-on-meaning-form-and-understanding-in-the-age-of-data-2020","title":"Climbing towards NLU: On Meaning, Form, and Understanding in the Age of Data (2020)","text":"This paper argues that the modern NLP models trained on form has no abilities in understanding natural languages based on both the science and philosophy theories. It is structured as follows. In section Large LMs: Hype and analysis, this paper samples example pieces from news and academic literature that exaggerate the understanding abilities in using words including \"understand\"\"comprehension\"\"recall factual knowledge\", and argues that the current LMs have the ability no other than learning the surface linguistic forms of language rather than understanding them. In section What is meaning?, this paper clarifies the meaning of language as the communicative intent that a parole intends to express, and distinguishes the concept \"meaning\" and \"truth\" as the truth is the meaning that is \"grounded\" to the real world. In section The octopus test, this paper detailedly tells a thought experiment of a super intelligent octopus who can mimic the human response by never receiving the knowledge of the grounded real world of the language meaning, by which this paper argues that it might be that how the language receiver decodes the communicative intends affects the conventional meaning of language. In section More constrained thought experiments, two more thought experiments are provided, training the JAVA and training the English LMs without providing the executing methods the communicative intends, and the paper argues that such tasks are impossible. In section Human language acquisition, this paper supports its idea by providing the example of human children's acquiring knowledge is not only grounded on the world image, but also in the interaction with other people. In section Distributional semantics, this paper argues that in NLP, two methods based on the instincts above are training distributional models on corpora augmented with perceptual data, and looking to interaction data (according to Wittgenstein's \"meaning in use\").
"},{"location":"DL/NLPTheory/explainable_nlp/#information-theory-based-compositional-distributional-semantics-2021","title":"Information Theory-based Compositional Distributional Semantics (2021)","text":"According to the abstract, the contribution of this paper can be concluded as proposing the notion of Information Theory-based Compositional Distributional Semantics (ICDS): (i) We first establish formal properties for embedding, composition, and similarity functions based on Shannon\u2019s Information Theory; (ii) we analyze the existing approaches under this prism, checking whether or not they comply with the established desirable properties; (iii) we propose two parameterizable composition and similarity functions that generalize traditional approaches while fulfilling the formal properties; and finally (iv) we perform an empirical study on several textual similarity datasets that include sentences with a high and low lexical overlap, and on the similarity between words and their description. In section Introduction, the author introduces Frege's concepts of compositionality and contextuality, which respectively refers to that \"the meaning of the whole is a function of the meaning of its parts and the syntactic way in which they are combined\", and that \"the meaning of words and utterances is determined by their context\". This section also introduces the main concern of lacking systematicity by the linguists to the NLP, where systematicity is defined as \"A system is said to exhibit systematicity if, whenever it can process a sentence, it can process systematic variants, where systematic variation is understood in terms of permuting constituents or (more strongly) substituting constituents of the same grammatical category.\" Thus, this section introduces that this paper aims to propose a novel system called Information Theory-based Compositional Distributional Semantics (ICDS). In section Related Work, the author introduces a set of properties in selective proper text representation paradigms which includes \"systematicity\", \"usage context\", \"continuity\", and \"information measurbility\", and introduces a series of previous work under this standard. In section Theoretical Framework, this paper first establishes a geometric interpretation of ICDS, that \"The direction of an embedding represents the pragmatic meaning, and the vector norm of embedding represents how much information the literal utterance provides about its meaning in the pragmatic context\", and then proposes the concept of ICDS as \"there are minimal linguistic units whose semantics are determined by their use and whose amount of information is determined by their specificity. On the other hand, the systematicity of language can be captured by compositional mechanisms while preserving the amount of information of the composite utterance\". Section Formal Definition and Properties formally defines the concepts involved in ICDS, where (\\(\\pi\\),\\(\\delta\\), \\(\\bigodot\\)) stand for \"embedding\", \"semantic similarity\", and \"composition function\" respectively. This section points out the embedding function properties (information measurability and angular isometry), composition function properties (composition neutral element, composition norm monotonicity, and sensitivity to stricture), and similarity function properties (angular distance simialrity monotonicity, orthogonal embedding similarity monotonicity, and equidistant embedding simialrity monotonicity). In section Function Analysis and Generalization, this research evaluates several current embedding vector with the proposed framework, while in section Experiment, the semantic representation abilities of several prevailing LLMs including BERT and GPT are evaluated.
"},{"location":"DL/NLPTheory/explainable_nlp/#contrastive-explanations-for-model-interpretability-2021","title":"Contrastive Explanations for Model Interpretability (2021)","text":"This paper proposes a data augmentation method to generate counterexample on the bases of NLI datasets, and proves that by training on patterns \"why A rather than B\" with contrastive learning methods, the model performs better than the previous NLI baselines.
"},{"location":"DL/NLPTheory/explainable_nlp/#using-counterfactual-contrast-to-improve-compositional-generalization-for-multi-step-quantitative-reasoning-2023","title":"Using counterfactual contrast to improve compositional generalization for multi-step quantitative reasoning (2023)","text":""},{"location":"DL/NLPTheory/ling_ebender/","title":"Linguistics Fundamentals for Natural Lanaguage Processing \u7b14\u8bb0","text":"Emily Bender, 2013
100 Essentials from Morphology and Syntax
(\u534a\u5c0f\u65f6\u91cf\u5b50\u6ce2\u52a8\u901f\u8bfb\u6311\u6218 \u5148\u7528\u4e2d\u6587\u5199\u4e86)
from Contents
Lexical Semantics: Senses
Semantic Roles
Collocations and Other Multiword Expressions (MWEs)
Compositional Semantics \u6210\u5206\u8bed\u4e49
Compositional Semantics beyond Predicate-Argument Structure (TODO)
Beyond Sentences
Reference Resolution \u6307\u4ee3\u6d88\u89e3
Presupposition
Information Status and Information Structure
Implicature and Dialogue
The math word problem (MWP) aims to solve simple primary school math problems (in plain-text format) with deep learning methods. The problems usually consists of numbers no larger than 100 and only 5 operators (+, -, *, / and =). This blog is structured as follows. The Dataset part will introduce two main types, one indicating the locations of variables, and the other simply embedding the math formula within the natural language texts. The Methods parts will introduce several prevailing methods in solving this task, including both the models and workflows that improves the accuracy of models.
"},{"location":"DL/NLPTheory/mwp/#surveys","title":"Surveys","text":""},{"location":"DL/NLPTheory/mwp/#the-gap-of-semantic-parsing-a-survey-on-automatic-math-word-problem-solvers-2019","title":"The Gap of Semantic Parsing: A Survey on Automatic Math Word Problem Solvers (2019)","text":"This survey provides a comprehensive introduction to the MWP datasets and methods prior to 2019. This survey defines three stages of MWP solving, the Rule-based matching stage (1960-2010), Semantic parsing, feature engineering and statistical learning stage (2011-2017), and Deep learning and reinforcement learning stage (2017-2019).
"},{"location":"DL/NLPTheory/mwp/#towards-tractable-mathematical-reasoning-challenges-strategies-and-opportunities-for-solving-math-word-problems-2021","title":"Towards Tractable Mathematical Reasoning: Challenges, Strategies, and Opportunities for Solving Math Word Problems (2021)","text":"This survey introduces the contemporary MWP datasets til 2021, and methods including rule-based, and neural network encoder-decoder structures. Specifically, this paper concludes three strategies for math word solving, (i) direct answer generation, (ii) expression tree generation for inferring answers, and (iii) template retrieval for answer computation. Considering the type of problem solving method, this paper concludes two classes. The first class is non-neural approaches (rule-base or pattern matching approaches, semantic parsing, and statistical machine learning approaches), within which a particular strategy of applying domain knowledge in classifying the problems (e.g. into change, part-whole and compare classes). The second class is neural approaches, including intuitions of (i) predicting the answer directly (ii) generating a set of equations or mathematical expressions and inferring answers from the by executing them (iii) retrieving the templates from a pool of templates derived from training data and augmenting numerical quantities to compute the answer. These neural approaches generally follow encoder-decoder architectures, which fall in four types (i) seq-to-seq (ii) Transformer-to-tree (iii) seq-to-tree (iv) graph-to-tree. Among the four methods, the tree-structured decoder attend both parents and siblings to generate the next token, while the bottom-up representation of sub-tree of a sibling could further help to derive better outcomes. The graph-based encoder aims to learn different types of relationships among the constituents of MWPs. This section also mentions that \"Data augmentation is a popular preprocessing technique to increase the size of training data\" (reverse operation-based augmentation techniques, different traversal orders of expression trees, and weak supervision). In section Math Reasoning in Neural Approaches, this paper mentions several further topics under math reasoning, interpretability and explainability, infusing explicit and definitive knowledge, and reinforcement learning.
"},{"location":"DL/NLPTheory/mwp/#datasets","title":"Datasets","text":""},{"location":"DL/NLPTheory/mwp/#mawps-a-math-word-problem-repository-2016","title":"MAWPS: A Math Word Problem Repository (2016)","text":"sroy9/mawps: Code for MAWPS: A Math Word Problem Repository (github.com) The data format is as follows.
[\n{\n\"iIndex\": 1,\n\"sQuestion\": \"Joan found 70.0 seashells on the beach. She gave Sam some of her seashells . She has 27.0 seashells . How many seashells did she give to Sam ?\",\n\"lEquations\": [\"X=(70.0-27.0)\"],\n\"lSolutions\": [43.0]\n},\n]\n
"},{"location":"DL/NLPTheory/mwp/#math23k-deep-neural-solver-for-math-word-problems-2017","title":"Math23k: Deep Neural Solver for Math Word Problems (2017)","text":"Deep Neural Solver for Math Word Problems (aclanthology.org) This dataset is in Chinese.
Problem: Dan have 2 pens, Jessica have 4 pens. How many pens do they have in total ? \nEquation: x = 4+2 \nSolution: 6\n
"},{"location":"DL/NLPTheory/mwp/#mathqa-2019","title":"MathQA (2019)","text":"MathQA-Dataset (math-qa.github.io) This paper proposes a math dataset which enhances the AQuA dataset by providing fully-specified operational programs. This dataset has a diverse range of operators.
"},{"location":"DL/NLPTheory/mwp/#math-2021","title":"MATH (2021)","text":"arxiv.org/pdf/2103.03874.pdf MATH is a LaTeX format dataset, with its answer highlighted in a square block.
"},{"location":"DL/NLPTheory/mwp/#svmap","title":"SVMAP","text":"arkilpatel/SVAMP: NAACL 2021: Are NLP Models really able to Solve Simple Math Word Problems? (github.com) This dataset does not distinguish the data with the texts. An example data is as follows.
"},{"location":"DL/NLPTheory/mwp/#gsm8k-grade-school-math-2021","title":"GSM8k: grade school math (2021)","text":"Collected by OpenAI, this dataset consists of math problems in natural language descriptions, with the math formulas highlighted with special notes.The numbers are not explicitly highlighted with special symbols. Several examples of the data format are as follows.
"},{"location":"DL/NLPTheory/mwp/#draw","title":"DRAW","text":"Providing 1000 grounded word problems.
"},{"location":"DL/NLPTheory/mwp/#algebra","title":"Algebra","text":""},{"location":"DL/NLPTheory/mwp/#asdiv","title":"AsDiv","text":""},{"location":"DL/NLPTheory/mwp/#multiarith","title":"MultiArith","text":""},{"location":"DL/NLPTheory/mwp/#singleeq","title":"SingleEq","text":""},{"location":"DL/NLPTheory/mwp/#methods","title":"Methods","text":""},{"location":"DL/NLPTheory/mwp/#models","title":"Models","text":"Prior to 2017, the models for solving MWP are mainly concerning with neural networks. After Transformer has been released in 2017, attention-based models have been thriving. The novel models based on Transformer are mainly modifying the encoder and decoder structures, among which there are graph-encoder and tree-decoders.
"},{"location":"DL/NLPTheory/mwp/#graph-to-tree-learning-for-solving-math-word-problems-2020","title":"Graph-to-Tree Learning for Solving Math Word Problems (2020)","text":"This paper proposes a attention-based model Graph2Tree, consisting of graph-based encoder and a tree-based decoder. The math word problems are constructed into Quantity Comparison Graph.
"},{"location":"DL/NLPTheory/mwp/#math-word-problem-solving-with-explicit-numerical-values-2021","title":"Math Word Problem Solving with Explicit Numerical Values (2021)","text":""},{"location":"DL/NLPTheory/mwp/#math23k","title":"Math23K","text":"A novel approach called NumS2T is proposed to solve MWP. NumS2T is constructed with (a) an attention-based seq2seq model to generate its math expressions, (b) a numerical value encoder to obtain the number-aware problem state which are then concatenated with the problem hidden state in (a) to obtain number-aware problem representation, and (c) a numerical properties prediction mechanism for comparing the paired numerical values, determining the category of each numeral and measuring whether they should appear in the target expression.!
"},{"location":"DL/NLPTheory/mwp/#learning-to-reason-deductively-math-word-problem-solving-as-complex-relation-extraction-2022","title":"Learning to Reason Deductively: Math Word Problem Solving as Complex Relation Extraction (2022)","text":"This paper proposes a novel approach
"},{"location":"DL/NLPTheory/mwp/#workflows","title":"Workflows","text":"Most of the recent works follow the method of knowledge distilling, which means to generate high quality data with LLMs and then train a small model with the generated (and sometimes then augmented) data. The workflow of such tasks mainly assembles that of the following paper.
"},{"location":"DL/NLPTheory/mwp/#large-language-models-are-reasoning-teachers","title":"Large Language Models Are Reasoning Teachers","text":"This paper proposes a knowledge distilling method in solving math reasoning problems.
"},{"location":"DL/NLPTheory/mwp/#solving-math-word-problems-via-cooperative-reasoning-induced-language-models-acl-2023","title":"Solving Math Word Problems via Cooperative Reasoning induced Language Models (ACL 2023)","text":"This paper develops a cooperative reasoning-induced PLM for solving MWPs called Cooperative Reasoning (CoRe), with a generator to generate reasoning paths and a verifier to supervise the evaluation.
"},{"location":"DL/NLPTheory/mwp/#scaling-relationship-on-learning-mathematical-reasoning-with-large-language-models-2023","title":"Scaling Relationship on Learning Mathematical Reasoning with Large Language Models (2023)","text":""},{"location":"DL/NLPTheory/mwp/#gsm8k","title":"GSM8k","text":"This paper mainly focus on the following two questions: (i) Which is a better performance indicator of LLMs? (pre-training loss amount/model size) (ii) How to improve small model's performance by data augmentation? To answer the second question, this paper proposes a novel methods in data augmentation in the LLM data generation step which is called Rejection Finetuning (RFT). The algorithm of sampling data in RFT mainly adopts the thought of rejection sampling, which is expressed in the following pseudo-code. This paper assumes such an algorithm will yield as many as possible diverse reasoning paths. The workflow of the RFT method is illustrated as follows, where the SFT stands for supervised finetuning. With the novel method RFT, small models such as Llama-7b yields an accuracy of at most 49.7% on GSM8k, 14% higher than the previous SOTA method SFT.
"},{"location":"DL/NLPTheory/mwp/#pal","title":"PAL","text":"This work is a prompt engineering work.
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? \nA: Roger started with 5 tennis balls. tennis_balls = 5 2 cans of 3 tennis balls each is bought_balls = 2 * 3 tennis balls. The answer is answer = tennis_balls + bought_balls \nQ: The bakers at the Beverly Hills Bakery baked 200 loaves of bread on Monday morning. They sold 93 loaves in the morning and 39 loaves in the afternoon. A grocery store returned 6 unsold loaves. How many loaves of bread did they have left?\n
A: The bakers started with 200 loaves loaves_baked = 200 They sold 93 in the morning and 39 in the afternoon loaves_sold_morning = 93 loaves_sold_afternoon = 39 The grocery store returned 6 loaves. loaves_returned = 6 The answer is answer = loaves_baked - loaves_sold_morning - loaves_sold_afternoon + loaves_returned\n
"},{"location":"DL/NLPTheory/mwp/#preview","title":"Preview","text":""},{"location":"DL/NLPTheory/neural_symbolic/","title":"Neural Symbolic AI","text":"TODO
Neural-Symbolic Computing: An Effective Methodology for Principled Integration of Machine Learning and Reasoning This paper provides an introduction to neural symbolic computing, indicating that the neural symbolic AI aim at integrating as learning from the environment and the ability to reason from what has been learned.
"},{"location":"DL/NLPTheory/nli/","title":"Natural Language Inference (NLI)","text":"TODO: \u786e\u5b9a\u5199\u4e0d\u51fa\u6765\u5148\u653e\u5f03\u5427
"},{"location":"DL/NLPTheory/nli/#task-description","title":"Task Description","text":"Natural Language Inference (NLI) problem concerns the logic reasoning relationship of sentences or facts in natural language texts.
"},{"location":"DL/NLPTheory/nli/#relevant-survey","title":"Relevant Survey","text":"There are several relevant surveys on the NLI tasks.
"},{"location":"DL/NLPTheory/nli/#a-survey-of-paraphrasing-and-textual-entailment-method-2017","title":"A survey of paraphrasing and textual entailment method (2017)","text":"https://www.jair.org/index.php/jair/article/view/10651
"},{"location":"DL/NLPTheory/nli/#an-overview-of-natural-language-inference-data-collection-the-way-forward-2017","title":"An overview of Natural Language Inference Data Collection: The way forward? (2017)","text":"https://aclanthology.org/W17-7203.pdf
"},{"location":"DL/NLPTheory/nli/#logical-formalizations-of-commonsense-reasoning-a-survey-2017","title":"Logical formalizations of commonsense reasoning: a survey (2017)","text":"https://www.jair.org/index.php/jair/article/view/11076/26258
"},{"location":"DL/NLPTheory/nli/#recent-advances-in-natural-language-inference-a-survey-of-benchmarks-resources-and-approaches-2019","title":"Recent Advances in Natural Language Inference: A Survey of Benchmarks, Resources, and Approaches (2019)","text":"https://arxiv.org/abs/1904.01172
"},{"location":"DL/NLPTheory/nli/#a-survey-on-recognizing-textual-entailment-as-an-nlp-evaluation-2020","title":"A Survey on Recognizing Textual Entailment as an NLP Evaluation (2020)","text":"https://aclanthology.org/2020.eval4nlp-1.10.pdf
"},{"location":"DL/NLPTheory/nli/#symbolic-and-neural-approaches-to-natural-language-inference-2021","title":"SYMBOLIC AND NEURAL APPROACHES TO NATURAL LANGUAGE INFERENCE (2021)","text":"https://scholarworks.iu.edu/dspace/bitstream/handle/2022/26642/dissertation_final_hai_hu.pdf?sequence=1&isAllowed=y
"},{"location":"DL/NLPTheory/nli/#natural-language-inference-a-dissertation-bill-maccartney","title":"Natural Language Inference a dissertation (BIll MacCartney)","text":"https://www-nlp.stanford.edu/~wcmac/papers/nli-diss.pdf
"},{"location":"DL/NLPTheory/nli/#toward-reasoning-in-large-language-models-a-survey","title":"Toward reasoning in large language models: A survey","text":"https://arxiv.org/abs/2212.10403 The structure of this paper is as follows. This paper first provides differentiations among deductive reasoning, inductive reasoning and abductive reasoning, and among formal reasoning and informal reasoning. At the end, this paper states that it focuses explicitly in informal deductive reasoning in large language models. Deductive reasoning
Premise: All mammals have kidneys. \nPremise: All whales are mammals. \nConclusion: All whales have kidneys.\n
Inductive reasoning Observation: Every time we see a creature with wings, it is a bird. \nObservation: We see a creature with wings. \nConclusion: The creature is likely to be a bird.\n
Abductive reasoning Observation: The car cannot start and there is a puddle of liquid under the engine. \nConclusion: The most likely explanation is that the car has a leak in the radiator.\n
In the Towards Reasoning in Large Language Models section, this survey discusses three main methods in solving math reasoning problems. For fully supervised fine-tuning method, it is suggested that the two main limitations are the lack of the datasets containing explicit reasoning, and the lack of the generializability of models. For CoT methods, this paper introduces CoT as a trigger of LLMs reasoning ability, and introduces several variant of CoT including zero-shot CoT, and three methods towards Rationale engineering, Rational refinement (complexity-based prompting, algorithmic prompting, and Auto-CoT), Rationale exploration (self-consistency probing), and Rationale verification. The Hybrid Method section introduces the Reasoning-Enhanced Training and Prompting and the Bootstrapping & Self-Improving methods. In section Measuring Reasoning in Large Language Models, this paper introduces several task variants to the reasoning task, including Arithmetic Reasoning, Commonsense Reasoning and Symbolic Reasoning. Four findings are proposed in this survey, which are that \"Reasoning seems an emergent ability of LLMs\", \"CoT elicits reasoning of LLMs\", \"LLMs show human-like content effect on reasoning\", and \"LLMs are still unskilled at complex reasoning\". This paper also points out concerns on whether LLMs are reasoning or simply \"generating reasoning-like responses\".
"},{"location":"DL/NLPTheory/nli/#dataset","title":"Dataset","text":"The natural language reasoning datasets usually follows the multiple choice structure -- given a premise consisting of a series of sentences and a hypothesis of usually one-sentence length, the label indicates the relationship between them, which are \"entailment\", \"neutral\" or \"contradiction\". According to the length of the premises, the NLI datasets can be classified as sentence-level, paragraph-level and document-level.
"},{"location":"DL/NLPTheory/nli/#sentence-level","title":"Sentence-level","text":""},{"location":"DL/NLPTheory/nli/#paragraph-level","title":"Paragraph-level","text":""},{"location":"DL/NLPTheory/nli/#document-level","title":"Document-level","text":""},{"location":"DL/NLPTheory/nli/#method","title":"Method","text":""},{"location":"DL/NLPTheory/nli/#sentence-level_1","title":"Sentence-level","text":""},{"location":"DL/NLPTheory/nli/#paragraph-level_1","title":"Paragraph-level","text":""},{"location":"DL/NLPTheory/nli/#document-level_1","title":"Document-level","text":""},{"location":"DL/NLPTheory/nli/#preview","title":"Preview","text":""},{"location":"DL/Python/broadcastable_vector/","title":"Broadcastble Vector","text":"Broadcasting is a mechanism which allows tensors with different numbers of dimensions to be added or multiplied together by (virtually) replicating the smaller tensor along the dimensions that it is lacking.
One tensor is broadcastable to another if the following rules hold. - Each tensor has at least one dimension. - When iterating over the dimension size, starting at the trailing dimension, the dimension sizes must either be equal, one of them is 1, or one of them does not exist.
Examples Same shapes are always broadcastable.
x = torch.empty(5,7,3)\ny = torch.empty(5,7,3)\n
If one of the vectors does not have at least one dimension, they are not broadcastable.
x = torch.empty((0,))\ny = torch.empty(2,2)\n
Lining up is from right to left. x and y can line up trailing dimensions
x = torch.empty(5, 3, 4, 1)\ny = torch.empty( 3, 1, 1)\n
1st trailing dimension: x and y both have dim 1 2nd trailing dimension: y has 1 3rd trailing dimension: x = y 4th trailing dimension: y's dimension does not exist"},{"location":"DL/Python/ipdb/","title":"IPDB","text":"Python\u8c03\u8bd5\u5de5\u5177
\u5b89\u88c5
pip install ipdb\n
\u4f7f\u7528
import ipdb\n# some code\nx = 10\nipdb.set_trace()\ny = 20\n# other code\n
\u6216\u8005\u4f7f\u7528\u547d\u4ee4\u884c
python -m ipdb your_code.py\n
"},{"location":"DL/Python/pandas_dataframe/","title":"Pandas Dataframe","text":"\u63d0\u793a\uff1a\u4f46\u662fpandas\u771f\u7684\u96be\u7528\uff0c\u91cc\u9762\u5b9e\u73b0\u633a\u4e71\u7684\uff0c\u7ecf\u5e38\u51fa\u73b0\u672a\u77e5\u7684\u526f\u4f5c\u7528\uff08\u4e5f\u53ef\u80fd\u602a\u6211db\u6ca1\u5b66\u597dorz\uff09\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528csv\u5305
\u53c8\u53c8\uff1apandas\u597d\u50cf\u6700\u8fd1\uff08\u630723\u5e7411\u6708\uff09\u6709\u4e2a\u62df\u4eba\u4e00\u70b9\u7684\u66f4\u65b0\uff0c\u6211\u8e72\u4e00\u8e72
"},{"location":"DL/Python/pandas_dataframe/#_1","title":"\u589e","text":"\u6309\u5217\u589e\u52a0
citys = ['ny','zz','xy']\ndf.insert(0,'city',citys) #\u5728\u7b2c0\u5217\uff0c\u52a0\u4e0acolumn\u540d\u79f0\u4e3acity\uff0c\u503c\u4e3acitys\u7684\u6570\u503c\u3002\njobs = ['student','AI','teacher']\ndf['job'] = jobs #\u9ed8\u8ba4\u5728df\u6700\u540e\u4e00\u5217\u52a0\u4e0acolumn\u540d\u79f0\u4e3ajob\uff0c\u503c\u4e3ajobs\u7684\u6570\u636e\u3002\ndf.loc[:,'salary'] = ['1k','2k','2k','2k','3k'] #\u5728df\u6700\u540e\u4e00\u5217\u52a0\u4e0acolumn\u540d\u79f0\u4e3asalary\uff0c\u503c\u4e3a\u7b49\u53f7\u53f3\u8fb9\u6570\u636e\u3002\n
\u6309\u884c\u589e\u52a0
df.loc[4] = ['zz','mason','m',24,'engineer\u2019] #\u82e5df\u4e2d\u6ca1\u6709index\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\u7684\u8bdd\uff0c\u8be5\u884c\u4ee3\u7801\u4f5c\u7528\u662f\u5f80df\u4e2d\u52a0\u4e00\u884cindex\u4e3a\u201c4\u201d\uff0c\u503c\u4e3a\u7b49\u53f7\u53f3\u8fb9\u503c\u7684\u6570\u636e\u3002\u82e5df\u4e2d\u5df2\u7ecf\u6709index\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\uff0c\u5219\u8be5\u884c\u4ee3\u7801\u4f5c\u7528\u662f\u628adf\u4e2dindex\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\u4fee\u6539\u4e3a\u7b49\u53f7\u53f3\u8fb9\u6570\u636e\u3002\ndf_insert = pd.DataFrame({'name':['mason','mario'],'sex':['m','f'],'age':[21,22]},index = [4,5])\nndf = df.append(df_insert,ignore_index = True) #\u8fd4\u56de\u6dfb\u52a0\u540e\u7684\u503c\uff0c\u5e76\u4e0d\u4f1a\u4fee\u6539df\u7684\u503c\u3002ignore_index\u9ed8\u8ba4\u4e3aFalse\uff0c\u610f\u601d\u662f\u4e0d\u5ffd\u7565index\u503c\uff0c\u5373\u751f\u6210\u7684\u65b0\u7684ndf\u7684index\u91c7\u7528df_insert\u4e2d\u7684index\u503c\u3002\u82e5\u4e3aTrue\uff0c\u5219\u65b0\u7684ndf\u7684index\u503c\u4e0d\u4f7f\u7528df_insert\u4e2d\u7684index\u503c\uff0c\u800c\u662f\u81ea\u5df1\u9ed8\u8ba4\u751f\u6210\u3002\n
"},{"location":"DL/Python/pandas_dataframe/#_2","title":"\u5220","text":"\u5220\u9664\u884c
df.drop([1,3],axis = 0,inplace = False)#\u5220\u9664index\u503c\u4e3a1\u548c3\u7684\u4e24\u884c\uff0c\n
\u5220\u9664\u5217
df.drop(['name'],axis = 1,inplace = False) #\u5220\u9664name\u5217\u3002\ndel df['name'] #\u5220\u9664name\u5217\u3002\nndf = df.pop('age\u2019)#\u5220\u9664age\u5217\uff0c\u64cd\u4f5c\u540e\uff0cdf\u90fd\u4e22\u6389\u4e86age\u5217,age\u5217\u8fd4\u56de\u7ed9\u4e86ndf\u3002\n
"},{"location":"DL/Python/pandas_dataframe/#_3","title":"\u6539","text":"\u6539\u884c\u5217\u6807\u9898
df.columns = ['name','gender','age'] #\u5c3d\u7ba1\u6211\u4eec\u53ea\u60f3\u628a\u2019sex\u2019\u6539\u4e3a\u2019gender\u2019\uff0c\u4f46\u662f\u4ecd\u7136\u8981\u628a\u6240\u6709\u7684\u5217\u5168\u5199\u4e0a\uff0c\u5426\u5219\u62a5\u9519\u3002\ndf.rename(columns = {'name':'Name','age':'Age'},inplace = True) #\u53ea\u4fee\u6539name\u548cage\u3002inplace\u82e5\u4e3aTrue\uff0c\u76f4\u63a5\u4fee\u6539df\uff0c\u5426\u5219\uff0c\u4e0d\u4fee\u6539df\uff0c\u53ea\u662f\u8fd4\u56de\u4e00\u4e2a\u4fee\u6539\u540e\u7684\u6570\u636e\u3002\ndf.index = list('abc')#\u628aindex\u6539\u4e3aa,b,c.\u76f4\u63a5\u4fee\u6539\u4e86df\u3002\ndf.rename({1:'a',2:'b',3:'c'},axis = 0,inplace = True)#\u65e0\u8fd4\u56de\u503c\uff0c\u76f4\u63a5\u4fee\u6539df\u7684index\u3002\n
\u6539\u6570\u503c
df.loc[1,'name'] = 'aa' #\u4fee\u6539index\u4e3a\u20181\u2019\uff0ccolumn\u4e3a\u2018name\u2019\u7684\u90a3\u4e00\u4e2a\u503c\u4e3aaa\u3002\ndf.loc[1] = ['bb','ff',11] #\u4fee\u6539index\u4e3a\u20181\u2019\u7684\u90a3\u4e00\u884c\u7684\u6240\u6709\u503c\u3002\ndf.loc[1,['name','age']] = ['bb',11] #\u4fee\u6539index\u4e3a\u20181\u2019\uff0ccolumn\u4e3a\u2018name\u2019\u7684\u90a3\u4e00\u4e2a\u503c\u4e3abb\uff0cage\u5217\u7684\u503c\u4e3a11\u3002\n
\u4f7f\u7528iloc[row_index, column_index]
df.iloc[1,2] = 19#\u4fee\u6539\u67d0\u4e00\u65e0\u7d20\ndf.iloc[:,2] = [11,22,33] #\u4fee\u6539\u4e00\u6574\u5217\ndf.iloc[0,:] = ['lily','F',15] #\u4fee\u6539\u4e00\u6574\u884c\n
"},{"location":"DL/Python/pandas_dataframe/#lociloc","title":"\u7b5b\u9009\u6570\u636e\u65b9\u6cd5loc\u3001iloc","text":"import pandas as pd\nimport numpy as np\ndates = pd.date_range('20200315', periods = 5)\ndf = pd.DataFrame(np.arange(20).reshape(5,4), index = dates, columns = ['A', 'B','C','D'])\nprint(df)\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n2020-03-18 12 13 14 15\n2020-03-19 16 17 18 19\n
print(df['A'])\n
#\u8f93\u51fa\n2020-03-15 0\n2020-03-16 4\n2020-03-17 8\n2020-03-18 12\n2020-03-19 16\nFreq: D, Name: A, dtype: int64\n
print(df.A)\n
#\u8f93\u51fa\n2020-03-15 0\n2020-03-16 4\n2020-03-17 8\n2020-03-18 12\n2020-03-19 16\nFreq: D, Name: A, dtype: int64\n
\u8de8\u8d8a\u591a\u884c\u6216\u8005\u591a\u5217
print(df[0:3])\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n
print(df['20200315' : '20200317'])\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n
"},{"location":"DL/Python/pandas_dataframe/#loc","title":"loc\u7eaf\u6807\u7b7e\u7b5b\u9009","text":"import pandas as pd\nimport numpy as np\ndates = pd.date_range('20200315', periods = 5)\ndf = pd.DataFrame(np.arange(20).reshape(5,4), index = dates, columns = ['A', 'B','C','D'])\nprint(df)\nprint('\\n')\nprint(df.loc['20200315']) #\u6253\u5370\u67d0\u4e00\u884c\u7684\u6807\u7b7e\nprint('\\n')\nprint(df.loc[:,['A', 'B']]) #\u6253\u5370A\u3001B\u5c5e\u6027\u7684\u6240\u6709\u884c\nprint('\\n')\nprint(df.loc['20200315', ['A', 'B','C']])\n
#\u8f93\u51fa\n A B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n2020-03-18 12 13 14 15\n2020-03-19 16 17 18 19\n\nA 0\nB 1\nC 2\nD 3\nName: 2020-03-15 00:00:00, dtype: int64\n\n A B\n2020-03-15 0 1\n2020-03-16 4 5\n2020-03-17 8 9\n2020-03-18 12 13\n2020-03-19 16 17\n\nA 0\nB 1\nC 2\nName: 2020-03-15 00:00:00, dtype: int64\n
"},{"location":"DL/Python/pandas_dataframe/#_4","title":"\u67e5","text":""},{"location":"DL/Python/pandas_dataframe/#_5","title":"\u904d\u5386","text":"iterrows(): \u6309\u884c\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u884c\u8fed\u4ee3\u4e3a(index, Series)\u5bf9\uff0c\u53ef\u4ee5\u901a\u8fc7row[name]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\u3002 itertuples(): \u6309\u884c\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u884c\u8fed\u4ee3\u4e3a\u5143\u7956\uff0c\u53ef\u4ee5\u901a\u8fc7row[name]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\uff0c\u6bd4iterrows()\u6548\u7387\u9ad8\u3002 iteritems():\u6309\u5217\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u5217\u8fed\u4ee3\u4e3a(\u5217\u540d, Series)\u5bf9\uff0c\u53ef\u4ee5\u901a\u8fc7row[index]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\u3002
"},{"location":"DL/Python/python_object/","title":"Python\u9762\u5411\u5bf9\u8c61\u8bed\u6cd5","text":""},{"location":"DL/Python/python_object/#class","title":"Class","text":"\u5e38\u89c1\u8fd0\u7b97\u7b26\u91cd\u8f7d\u65b9\u6cd5
"},{"location":"DL/Python/python_object/#operator-at","title":"operator at(@)","text":"An @
at the beginning of a line is used for a class and function decorator. Example:
class Pizza(object):\ndef __init__(self):\nself.toppings = []\ndef __call__(self, topping):\n# When using '@instance_of_pizza' before a function definition\n# the function gets passed onto 'topping'.\nself.toppings.append(topping())\ndef __repr__(self):\nreturn str(self.toppings)\npizza = Pizza()\n@pizza\ndef cheese(): # this function passes to topping()\nreturn 'cheese'\n@pizza\ndef sauce():\nreturn 'sauce'\nprint pizza\n# ['cheese', 'sauce']\n
def decorator(func):\nreturn func\n@decorator\ndef some_func():\npass\n
is equivalent to this code def decorator(func):\nreturn func\ndef some_func():\npass\nsome_func = decorator(some_func)\n
"},{"location":"DL/Python/python_object/#kwargs","title":"**kwargs","text":"kwargs is a parameter in Python's functions, which takes an arbitrary numbers of parameters. Usage:
def\u00a0print_keyword_args(**kwargs):\n# kwargs is a dict of the keyword args passed to the function\nfor\u00a0key, value\u00a0in\u00a0kwargs.iteritems():\nprint\u00a0\"%s = %s\"\u00a0% (key, value)\nprint_keyword_args(first_name=\"John\", last_name=\"Doe\")\n
Output: first_name = John last_name = Doe"},{"location":"DL/Python/python_object/#_1","title":"\u6570\u7ec4\u62f7\u8d1d","text":"s1 = [[]] * 3 ## \u662f\u6d45\u62f7\u8d1d\ns1[1].append('xyx') ## [['xyx'], ['xyx'], ['xyx']]\ns2 = [[] for _ in 3] ## \u662f\u6df1\u62f7\u8d1d\ns2[1].append('xyx') ## [[], ['xyx'], []]\n
"},{"location":"DL/Python/pytorch/","title":"Pytorch \u901f\u67e5","text":""},{"location":"DL/Python/pytorch/#nnmodulelist-and-nnsequential","title":"nn.ModuleList and nn.Sequential","text":"TLDR: nn.ModuleList
is a list which is indexable and without extra functions, while nn.Sequential
is a workflow with order and ability to call the forward functions automatically.
Please refer to more details from PyTorch \u4e2d\u7684 ModuleList \u548c Sequential: \u533a\u522b\u548c\u4f7f\u7528\u573a\u666f - \u77e5\u4e4e (zhihu.com).
"},{"location":"DL/Python/pytorch/#forward-function-in-pytorch","title":"Forward function in Pytorch","text":"In training models with Pytorch, there is no need to explicitly call the forward function. The way to call the forward function is as follows.
class Module(nn.Module):\ndef __init__(self):\nsuper().__init__()\n# ...\ndef forward(self, x):\n# ...\nreturn x\ndata = data\nmodel = Module()\nmodel(data)\n
instead of model.forward(data)
. This is because model(data)
equals mode.forward(data)
itself. In class nn.Module
, the function __call__
has been overloaded as def __call__(self, data):\nreturn self.forward(data)\n
"},{"location":"DL/Python/pytorch/#element-wise-matmul-dot","title":"*\u662felement wise @\u548cmatmul\u662f\u77e9\u9635\u76f8\u4e58 dot\u662f\u70b9\u4e58","text":"import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = tensor1 * tensor2\nprint(result) # Output: tensor([4, 10, 18])\n
import torch\ntensor1 = torch.tensor([[1, 2], [3, 4]])\ntensor2 = torch.tensor([[5, 6], [7, 8]])\nresult = tensor1 @ tensor2\nprint(result) # Output: tensor([[19, 22], [43, 50]])\n
import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = torch.dot(tensor1, tensor2)\nprint(result) # Output: tensor(32)\n
import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = torch.dot(tensor1, tensor2)\nprint(result) # Output: tensor(32)\n
"},{"location":"DL/Python/pytorch/#to-train-the-model-with-gpu","title":"To train the model with GPU","text":"import torch\n# Step 1: Check for GPU availability\nif torch.cuda.is_available():\ndevice = torch.device('cuda')\nelse:\ndevice = torch.device('cpu')\n# Step 2: Move the model and data to the GPU\nmodel = YourModel().to(device)\ndata = YourData().to(device)\n# Step 3: Update the computation on the GPU\nmodel.to(device)\ndata = data.to(device)\n# Step 4: Perform training and inference\nfor epoch in range(num_epochs):\n# Training loop\nfor batch in data_loader:\ninputs, labels = batch\ninputs = inputs.to(device)\nlabels = labels.to(device)\n# Perform forward and backward pass, update model parameters\n# Inference\nwith torch.no_grad():\nfor batch in validation_data_loader:\ninputs, labels = batch\ninputs = inputs.to(device)\nlabels = labels.to(device)\n# Perform forward pass for evaluation\n
"},{"location":"DL/Python/setup_pack/","title":"Python Setup Packages","text":"\u7f16\u5199setup.py\u6587\u4ef6\u662f\u4e3a\u4e86\u4f7f\u7528Python\u7684setuptools\u6784\u5efa\u5b89\u88c5\u81ea\u5df1\u7684Python\u5305\u3002 \u4e00\u4e2asetup.py\u6587\u4ef6\u5e94\u5f53\u653e\u5728\u5305\u4ee3\u7801\u76ee\u5f55\u4e0b\u3002\u4f8b\u5982\u5305\u4ee3\u7801\u76ee\u5f55\u4e3a
your_package_name/\n__init__.py\nmodule1.py\nmodule2.py\nsetup.py\n
\u5176\u4e2dsetup.py\u7684\u5199\u6cd5\u662f from setuptools import setup\nsetup(\nname='YourPackageName',\nversion='1.0',\nauthor='Your Name',\nauthor_email='your@email.com',\ndescription='Description of your package',\npackages=['your_package_name'], # \u5305\u7684\u76ee\u5f55\u5217\u8868\u3002\u5982\u679c\u6709\u591a\u4e2a\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528find_packages()\u67e5\u627e\ninstall_requires=[ # \u8fd9\u4e9b\u4f9d\u8d56\u5c06\u81ea\u52a8\u5b89\u88c5 \n'dependency1',\n'dependency2',\n],\n)\n
\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0c\u5e94\u5f53\u5728\u547d\u4ee4\u884c\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f\u8fd0\u884c\u6253\u5305 python setup.py sdist bdist_wheel\n
\u7528\u5982\u4e0b\u65b9\u5f0f\u5b89\u88c5 pip install dist/YourPackageName-1.0.tar.gz\n
"},{"location":"DL/Terminal/anaconda/","title":"Anaconda \u5e38\u7528\u547d\u4ee4","text":""},{"location":"DL/Terminal/anaconda/#_1","title":"\u521b\u5efa\u73af\u5883","text":"conda create --name [ENV_NAME] python==3.9\n
"},{"location":"DL/Terminal/anaconda/#_2","title":"\u5220\u9664\u73af\u5883","text":" conda remove -n [ENV_NAME] --all\n
"},{"location":"DL/Terminal/anaconda/#_3","title":"\u67e5\u770b\u73b0\u5b58\u865a\u62df\u73af\u5883","text":"conda env list\n
"},{"location":"DL/Terminal/anaconda/#_4","title":"\u67e5\u770b\u76ee\u524d\u73af\u5883\u5df2\u5b89\u88c5\u5305","text":"conda list\n
"},{"location":"DL/Terminal/anaconda/#_5","title":"\u6253\u5f00\u73af\u5883","text":" conda activate [ENV_NAME]\n
"},{"location":"DL/Terminal/anaconda/#_6","title":"\u5173\u95ed\u73af\u5883","text":"conda deactivate\n
"},{"location":"DL/Terminal/anaconda/#_7","title":"\u5220\u9664\u73af\u5883\u4e2d\u7684\u67d0\u4e2a\u5305","text":"conda remove --name [ENV_NAME] [PACK_NAME]\n
Update specific package:
conda update [PACK_NAME]\n
Update all packages in the current environment:
conda update --all\n
Update all packages in the current environment:
conda update -n myenv --all\n
Update Python:
conda update python\n
Update conda itself:
conda update conda\n
TODO \u5728\u5199\u4e86\u8fd9\u4e2a\u771f\u7684\u5728\u5199\u4e86
\u5220\u9664\u6587\u4ef6
rm [FILENAME]\n
\u5220\u9664\u76ee\u5f55
rm -rf [PATH]\n
"},{"location":"DL/Terminal/pytorch_terminal/","title":"Pytorch \u547d\u4ee4\u884c\u547d\u4ee4","text":""},{"location":"DL/Terminal/pytorch_terminal/#install","title":"install","text":"(MacOS, conda, no GPU or CUDA)
conda install pytorch torchvision torchaudio -c pytorch\n
"},{"location":"DL/Terminal/pytorch_terminal/#20220112-cannot-import-name-field-from-torchtext","title":"2022/01/12 cannot import name \u2018Field\u2019 from \u2018torchtext\u2019","text":"\u65b0\u7248torchtext\u628afield\u7c7b\u5220\u4e86\uff0c\u2019.legacy\u2019\u4e5f\u68c0\u6d4b\u4e0d\u5230\uff0c\u7528\u7248\u672c\u56de\u9000
pip --default-timeout=100 install torchtext==0.10.0\n
"},{"location":"DL/Terminal/tmux/","title":"tmux","text":"install
git clone https://github.com/tmux/tmux.git\ncd tmux\nsh autogen.sh\n./configure && make\n
# Ubuntu \u6216 Debian\n$ sudo apt-get install tmux\n# CentOS \u6216 Fedora\n$ sudo yum install tmux\n\n# Mac\n$ brew install tmux\n
\u5f00\u542f\u65b0\u8fdb\u7a0b\u7684\u901a\u7528\u547d\u4ee4
tmux new-session -d -s my_session \\; send-keys \"<command>\" Enter\n
\u4e0a\u4f20\u6587\u4ef6\u7528ssh\u5230\u670d\u52a1\u5668
tmux new-session -d -s my_session \\; send-keys \"rsync filename username@ip_address:/home/username\" Enter\n
\u8fd0\u884cpython\u811a\u672c
tmux new-session -d -s <session name> \\; send-keys \"python3 <program name>.py\" Enter\n
\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b
tmux ls\n
\u6740\u6b7b\u8fdb\u7a0b
tmux kill-session -t <session name>\n
\u901a\u8fc7\u91cd\u5b9a\u5411\u8f93\u51fa\u5b9e\u73b0tmux\u4f1a\u8bdd\u4e2d\u4e0e\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u901a\u4fe1\u3002
tmux new-session -d -s <session name> \\; send-keys \"python3 <program name>.py > output.txt\" Enter\n
\u67e5\u770boutput.txt\u7684\u5185\u5bb9
cat output.txt\n
\u5b9e\u65f6\u76d1\u6d4b\u6587\u4ef6\u7684\u53d8\u5316 \u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u968f\u65f6\u663e\u793aoutput.txt\u7684\u5185\u5bb9
tail -f output.txt\n
ssh username@server_address tmux ls\n
ssh username@server_address tmux ls -t <session_name>\n
"},{"location":"Ling/","title":"\u7d22\u5f15","text":"\u672c\u4e13\u680f\u5305\u542b\u8bed\u8a00\u5b66\u7b14\u8bb0\uff0c\u76ee\u524d\u5df2\u5b8c\u6210\u4ee5\u4e0b\u5185\u5bb9
Aug. 25th. 2023
This talk aims both to provide an introduction to the subject Philosophy of Language (a similar subject with semantics and pragmatics, according to its definition; PoL hereafter), and give a summary on the recent ongoing discussion on the linguistics concepts in NLP (e.g. \"meaning\", \"understanding\", \"reasoning\", \"grounding\").
"},{"location":"Ling/pol_en_todo/#a-preview-of-this-talk","title":"A Preview of This Talk","text":"1st 40min: History of philosophy of language 2nd 40min: Recent papers and discussions on PoL topics in NLP 3rd 10min: Discussion on take-away
"},{"location":"Ling/pol_en_todo/#the-location-of-pol-on-the-academic-coordinate","title":"The Location of PoL on the Academic Coordinate","text":"Before we start this talk, we will first provide a brief definition of the term Philosophy of Language in our talk here. The PoL concerns mainly the two following questions, (i) The relationship between the natural language and the world, (ii) The relationship between the human languages and their meaning. Chen (2003) believes that the PoL and the linguistics are two different subjects. He suggests that the linguistics is the study of language rules and patterns and the application of them, while the PoL pays more attention on the more abstract and essential features of the human language (e.g. its relation to the cognition). The author of this talk believes, according to the definition of PoL, it is a subject that closely involves the semantics and pragmatics branches in linguistics. However the PoL and linguistics overlap or not, it is commonly believed that the subject PoL was born in the 1920s, when the linguistic turn was put on stage in the European philosophy.
"},{"location":"Ling/pol_en_todo/#history-of-pol","title":"History of PoL","text":"Now we will dive into the history of PoL. This section is parted \"person by person\". It is noticed that \"person-by-person\" is a common structure of most of the philosophy history, as most of the philosophy progresses are propelled by giants instead of the common people.
"},{"location":"Ling/pol_en_todo/#gottfried-wilhelm-leibniz","title":"Gottfried Wilhelm Leibniz","text":"The main contribution of Leibniz is
"},{"location":"Ling/pol_en_todo/#ferdinand-de-saussure","title":"Ferdinand de Saussure","text":""},{"location":"Ling/pol_en_todo/#friedrich-ludwig-gottlob-frege","title":"Friedrich Ludwig Gottlob Frege","text":""},{"location":"Ling/pol_en_todo/#bertrand-russell","title":"Bertrand Russell","text":"Bertrand Russell is a pure logician.
"},{"location":"Ling/pol_en_todo/#ludwig-wittgenstein","title":"Ludwig Wittgenstein","text":""},{"location":"Ling/pol_en_todo/#noam-chomsky","title":"Noam Chomsky","text":""},{"location":"Ling/pol_zh/","title":"Philosophy of Language \u8bed\u8a00\u54f2\u5b66","text":"Nov. 9th. 2022
"},{"location":"Ling/pol_zh/#talk","title":"\u8fd9\u6b21talk\u4f1a\u8bb2\u4ec0\u4e48","text":"\u2705\u00a0\u4ecb\u7ecd\u8bed\u8a00\u54f2\u5b66\u7684\u601d\u6f6e\u6d41\u53d8\u5386\u7a0b\uff0c\u4ecb\u7ecd\u8bed\u8a00\u4e0a\u7684\u5b9e\u9a8c\u601d\u60f3\u5b9e\u9a8c\uff0c\u8ba8\u8bba\u4e00\u4e9b\u8bed\u8a00\u5b66\u3001\u8ba4\u77e5\u3001\u903b\u8f91\u548c\u54f2\u5b66\u7684\u5173\u8054
"},{"location":"Ling/pol_zh/#pol","title":"PoL","text":"\u8bed\u8a00\u54f2\u5b66\u7684\u57fa\u672c\u95ee\u9898\uff1a 1. \u8bed\u8a00\u548c\u4e16\u754c\u7684\u5173\u7cfb 2. \u8bed\u8a00\u6216\u8bed\u8bcd\u7684\u610f\u4e49\u95ee\u9898
\u8bed\u8a00\u54f2\u5b66\u548c\u8bed\u8a00\u5b66 \u8bed\u8a00\u5b66\u548c\u8bed\u8a00\u54f2\u5b66\u7684\u8054\u7cfb\u7d27\u5bc6\uff0c\u4f46\u662f\u662f\u4e24\u95e8\u5b66\u79d1\u3002
20\u4e16\u7eaa\u54f2\u5b66\u4e0a\u53d1\u751f\u4e86\u8bed\u8a00\u8f6c\u5411\uff0c\u8fd9\u4e5f\u662f\u73b0\u4ee3\u8bed\u8a00\u5b66\u5f62\u6210\u7684\u65f6\u5019\u3002
\u8bed\u8a00\u5b66\u662f\u5bf9\u8bed\u8a00\u89c4\u5f8b\u548c\u8fd9\u4e9b\u89c4\u5f8b\u7684\u5e94\u7528\u7684\u7814\u7a76\uff0c\u8bed\u8a00\u54f2\u5b66\u66f4\u5173\u5fc3\u8bed\u8a00\u66f4\u672c\u8d28\u66f4\u62bd\u8c61\u7684\u610f\u4e49\u3002
"},{"location":"Ling/pol_zh/#history-of-pol","title":"History of PoL","text":"\u83b1\u5e03\u5c3c\u8328\uff1a\u63d0\u51fa\u903b\u8f91\u8bed\u8a00\uff0c\u7b80\u5386\u4eba\u5de5\u8bed\u8a00\u7684\u52aa\u529b
\u5f3a\u8c03\u81ea\u7136\u8bed\u8a00\u4f9d\u8d56\u4e8e\u77e5\u8bc6\uff0c\u56e0\u6b64\u5206\u6709\u77e5\u89c9\u7684\u6a21\u7cca\u3001\u6b67\u4e49\u7b49\u79cd\u79cd\u7f3a\u9677\u3002\u81ea\u7136\u8bed\u8a00\u4e0d\u662f\u63cf\u8ff0\u5ba2\u89c2\u4e8b\u7269\u7684\u6700\u4f73\u5de5\u5177\uff0c\u4e3a\u4e86\u63a2\u7a76\u771f\u7406\uff0c\u5fc5\u987b\u5efa\u7acb\u4e00\u4e2a\u7531\u666e\u904d\u7b26\u53f7\u7ec4\u6210\u7684\u66f4\u4e3a\u6e05\u695a\u7684\u7b26\u53f7\u4f53\u7cfb\u3002\u8fd9\u79cd\u52aa\u529b\u5728\u6570\u5b66\u65b9\u9762\u662f\u5353\u6709\u6210\u6548\u7684\uff0c\u6bd4\u5982\u5fae\u79ef\u5206\u7b26\u53f7\u3002
\u7d22\u7eea\u5c14\uff1a \u7d22\u7eea\u5c14\u6700\u5927\u7684\u5f71\u54cd\u662f\u300a\u666e\u901a\u8bed\u8a00\u5b66\u300b\u3002\u6211\u4eec\u4e00\u822c\u8ba4\u4e3a\u7d22\u7eea\u5c14\u662f\u4e00\u4f4d\u8bed\u8a00\u5b66\u5bb6\uff0c\u4f46\u662f\u4ed6\u5728\u8fd9\u672c\u4e66\u4e2d\u63d0\u51fa\u7684\u201c\u80fd\u6307\u201d\u4e0e\u201c\u6240\u6307\u201d\u7406\u8bba\uff0c\u662f\u54f2\u5b66\u91cc\u7684\u7b26\u53f7\u5b66\u7684\u5f00\u7aef\u3002
\u8bed\u8a00\u662f\u7528\u58f0\u97f3\u8868\u8fbe\u601d\u60f3\u7684\u7b26\u53f7\u7cfb\u7edf\uff0c\u7b26\u53f7\u662f\u7528\u4ee5\u8868\u793a\u8005\u548c\u88ab\u8868\u793a\u8005\u7684\u7ed3\u5408\u3002
\u6211\u4eec\u4f1a\u8bf4\uff0c\u58f0\u97f3\u672c\u8eab\u4e0d\u80fd\u65bd\u6307\uff0c\u53ea\u6709\u5904\u5728\u67d0\u79cd\u7279\u5b9a\u5173\u7cfb\u4e2d\uff08\u8bed\u8a00\u5b9a\u4e49\u4e86\u58f0\u97f3\u548c\u5b9e\u4f53\u4e4b\u95f4\u7684\u5173\u7cfb\uff09\uff0c\u58f0\u97f3\u624d\u6709\u4e86\u610f\u4e49\u3002
\u4efb\u610f\u6027\u539f\u5219\u662f\uff0c\u5982\u6b64\u8fd9\u822c\u7684\u65bd\u6307\u548c\u5982\u6b64\u8fd9\u822c\u7684\u6240\u6307\u7ed3\u5408\u800c\u6210\u7684\u4e00\u4e2a\u7b26\u53f7\uff0c\u662f\u4efb\u610f\u7684\u3002eg. \u989c\u8272\u4e0e\u989c\u8272\u8bcd\u7684\u8054\u7ed3\u662f\u4efb\u610f\u7684\uff0c\u989c\u8272\u7684\u754c\u9650\u4e0e\u989c\u8272\u8bcd\u7684\u8054\u7ed3\u4e5f\u662f\u4efb\u610f\u7684\u3002
\"\u7eff\"\u4e0d\u4ec5\u548c\u7eff\u989c\u8272\u76f8\u8fde\uff0c\u800c\u4e14\u548c\u201c\u84dd\u201d\u201c\u9752\u201d\u7b49\u8bed\u8bcd\u76f8\u8fde\u3002\n\u5982\u679c\u6ca1\u6709\u201c\u84dd\u201d\u201c\u9752\u201d\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u77e5\u9053\u201c\u7eff\u201d\u6240\u754c\u5b9a\u7684\u989c\u8272\u8303\u56f4\u3002\n\n\u201c\u4e03\u8272\u5f69\u8679\u201d\n\u65e5\u8bed\u4e0d\u533a\u5206\u201c\u84dd\u201d\u548c\u201c\u7eff\u201d\uff0c\u53ea\u6709\u4e00\u4e2a\u5355\u8bcd\u201c\u9752\u201d\uff08aoi\uff09\uff0c\u65e5\u8bed\u6bcd\u8bed\u8005\u5728\u9274\u522b\u84dd\u8272\u548c\u7eff\u8272\u65f6\u53cd\u5e94\u65f6\u9ad8\u4e8e\u82f1\u8bed\u6bcd\u8bed\u8005\u3002\n\u4e00\u79cd\u5317\u6b27\u8bed\u8a00\u6709\u4e03\u79cd\u84dd\u8272\u7684\u540d\u79f0\u3002\n
\u6211\u4eec\u4e60\u60ef\u628a\u8bed\u8bcd\u548c\u60c5\u5883\u7684\u8054\u7cfb\u79f0\u4f5c\u7eb5\u5750\u6807\u6216\u8bed\u5883\u5750\u6807\uff0c\u628a\u8bed\u8bcd\u4e4b\u95f4\u7684\u8054\u7cfb\u79f0\u4f5c\u6a2a\u5750\u6807\u548c\u903b\u8f91\u5750\u6807\u3002
eg. \u5b8c\u5f62\u586b\u7a7a\u9898
eg. \u6570\u636e\u5e93\u5173\u7cfb\u6a21\u578b\u7684\u5c5e\u6027\u3001\u5143\u7ec4
\u975e\u5e38\u6709\u8da3\uff0c\u7d22\u7eea\u5c14\u5199\u8fd9\u672c\u8bed\u8a00\u5b66\u6559\u6750\u65f6\uff0c\u4e16\u754c\u4e0a\u5e76\u6ca1\u6709\u7b26\u53f7\u5b66\u8fd9\u4e2a\u5b66\u79d1\u3002\u5728\u4ed6\u63d0\u51fa\u201c\u80fd\u6307\u201d\u201d\u6240\u6307\u201c\u8fd9\u4e2a\u6982\u5ff5\u540e\uff0c\u7b26\u53f7\u5b66\u5728\u4ed6\u201d\u80fd\u6307\u201c\u5728\u201d\u6240\u6307\u201c\u7684\u94fe\u6761\u4e0a\u6ed1\u52a8\u8fd9\u4e00\u8bba\u65ad\u7684\u57fa\u7840\u4e0a\u8bde\u751f\uff0c\u5e76\u81f3\u4eca\u6210\u4e3a\u6cd5\u56fd\u54f2\u5b66\u7684\u4e00\u4e2a\u91cd\u8981\u95ee\u9898\u3002
\u5f17\u96f7\u683c\uff1a
\u5f17\u96f7\u683c\u662f\u516c\u8ba4\u7684\u5206\u6790\u54f2\u5b66\u3001\u8bed\u8a00\u54f2\u5b66\u548c\u73b0\u4ee3\u6570\u7406\u903b\u8f91\u7684\u5f00\u521b\u8005\u3002
\u300a\u6982\u5ff5\u6587\u5b57\uff1a\u4e00\u79cd\u6a21\u4eff\u7b97\u672f\u8bed\u8a00\u6784\u9020\u7684\u7eaf\u601d\u7ef4\u7684\u5f62\u5f0f\u8bed\u8a00\u300b\u4e3b\u8981\u5de5\u4f5c\u662f\uff0c\u8bbe\u8ba1\u4e86\u4e00\u5957\u4eba\u5de5\u7b26\u53f7\u7cfb\u7edf\uff0c\u6392\u9664\u4e86\u81ea\u7136\u8bed\u8a00\u4e2d\u4fee\u8f9e\u4e4b\u7c7b\u7684\u4e1c\u897f\uff0c\u4e13\u6ce8\u4e8e\u6982\u5ff5\u672c\u8eab\u548c\u6982\u5ff5\u4e4b\u95f4\u7684\u8054\u7cfb\uff0c\u56e0\u6b64\uff0c\u5b83\u5c06\u6392\u9664\u81ea\u7136\u8bed\u8a00\u7684\u6a21\u7cca\u6027\u548c\u4e0d\u786e\u5b9a\u6027\u3002\u7528\u8fd9\u5957\u7b26\u53f7\u7cfb\u7edf\u6765\u91cd\u65b0\u8868\u8ff0\u7b97\u672f\u7684\u57fa\u672c\u6982\u5ff5\u548c\u63a8\u7406\u89c4\u5219\uff0c\u660e\u786e\u6240\u6709\u63a8\u7406\u7684\u524d\u63d0\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u8bc1\u660e\u4e2d\u5404\u4e2a\u547d\u9898\u95f4\u7684\u6240\u6709\u63a8\u7406\u89c4\u5219\uff0c\u4f7f\u63a8\u7406\u4e0d\u518d\u57fa\u4e8e\u76f4\u89c9\uff0c\u4e5f\u6ca1\u6709\u8df3\u8dc3\u548c\u8131\u8282\u3002
\u5bf9\u8bed\u8a00\u54f2\u5b66\u5f71\u54cd\u6700\u6df1\u7684\u662f\u4ed6\u5728\u300a\u7b97\u672f\u57fa\u7840\u300b\u4e2d\u63d0\u51fa\u7684\u4e09\u6761\u8457\u540d\u539f\u5219\uff1a
\u4e24\u4e2a\u601d\u7ef4\u5b9e\u9a8c\uff1a
\u6307\u79f0\u76f8\u540c\u800c\u610f\u4e49\u4e0d\u540c\u7684\u8bcd
\u201c\u542f\u660e\u661f\u201d\u548c\u201c\u957f\u5e9a\u661f\u201d\u662f\u540c\u4e00\u9897\u884c\u661f\u2014\u2014\u2014\u2014\u91d1\u661f\u3002\n\u4f46\u662f\u4e24\u4e2a\u540d\u8bcd\u7684\u610f\u4e49\u4e0d\u540c\uff0c\u5927\u591a\u6570\u65f6\u5019\u4e0d\u80fd\u66ff\u6362\u3002\n\u201c\u4ed6\u5929\u8fd8\u6ca1\u4eae\u5c31\u8d77\u8eab\uff0c\u8fce\u7740\u542f\u660e\u661f\u5411\u4e1c\u8d70\u53bb\u3002\u201d\n
\u51fd\u5f0f\u7406\u8bba
\uff08 \uff09\u662f\u4e2d\u56fd\u7684\u9996\u90fd\n\uff08 \uff09= \"\u4f26\u6566\"\u3001\"\u5317\u4eac\"\n\u53ea\u6709\u586b\u5165\u5317\u4eac\u7684\u65f6\u5019\u624d\u662f\u771f\u547d\u9898\n
\u7f57\u7d20\uff1a\u903b\u8f91
\u6df1\u5165\u4e13\u540d\u548c\u901a\u540d\u3001\u6096\u8bba\u3001\u6392\u4e2d\u5f8b\u3002
\u7ef4\u7279\u6839\u65af\u5766\uff1a
\u524d\u671f\u601d\u60f3\u300a\u903b\u8f91\u54f2\u5b66\u8bba\u300b
\u201c\u4e16\u754c\u662f\u4e8b\u5b9e\u7684\u7efc\u5408\u201d\uff1a\u201c\u53f8\u9a6c\u5149\u662f\u5510\u671d\u4eba\u201d\u7b26\u5408\u903b\u8f91\uff0c\u4f46\u4e0d\u7b26\u5408\u4e8b\u5b9e\u3002
\u56fe\u50cf\u8bba
\u8bed\u8a00\u662f\u547d\u9898\u7684\u603b\u548c\u800c\u4e0d\u662f\u540d\u79f0\u7684\u603b\u548c\u3002
\u4eba\u5728\u4ea4\u6d41\u601d\u60f3/\u547d\u9898\u65f6\uff0c\u4ea4\u6d41\u7684\u662f\u8111\u4e2d\u7684\u56fe\u50cf\u3002
\u4ed6\u7684\u524d\u671f\u601d\u60f3\u542f\u53d1\u4e86\u7ef4\u4e5f\u7eb3\u5b66\u6d3e\uff1a\u4eba\u5de5\u8bed\u8a00\uff0c\u903b\u8f91\u8bed\u8a00
\u5341\u4e5d\u4e16\u7eaa\u672b\u4ee5\u6765\u4eba\u5de5\u8bed\u8a00\u7684\u5c1d\u8bd5\uff1a\u201c\u4e16\u754c\u8bed\uff08Esperanto\uff09\u201d\uff0c\u4e18\u5409\u5c14\u63a8\u5d07\u7684\u57fa\u672c\u82f1\u8bed\uff0c\u81ea\u7136\u8bed\u8a00\u4e2d\u5bf9\u201c\u5973\u4eba\u201d\u201c\u5973\u6027\u201d\u201c\u5973\u58eb\u201d\u201c\u5987\u5973\u201d\u8fd9\u6837\u7684\u6307\u79f0\u7684\u89c4\u8303\u5c1d\u8bd5\u3002
\u540e\u671f\u601d\u60f3\u300a\u54f2\u5b66\u7814\u7a76\u300b
\u8bed\u8a00\u6e38\u620f\uff08Sprachspiel\uff09
\u8bed\u8a00\u7684\u529f\u80fd\u7684\u672c\u8d28\uff1a\u4e00\u65b9\u558a\u51fa\u8bed\u8bcd\uff0c\u53e6\u4e00\u65b9\u4f9d\u7167\u8fd9\u4e9b\u8bed\u8bcd\u6765\u884c\u52a8\u3002
\u8001\u5e08\u6307\u7740\u77f3\u5934\u8bf4\u201c\u77f3\u5934\u201d\uff0c\u5b66\u751f\u8ddf\u7740\u8bf4\u201c\u77f3\u5934\u201d\u3002\n
\u4e22\u624b\u7ee2\u65f6\u5531\u7740\u201c\u8f7b\u8f7b\u5730\u653e\u5728\u5c0f\u670b\u53cb\u7684\u8eab\u540e\u201d\uff0c\u628a\u624b\u7ee2\u653e\u5728\u5c0f\u670b\u53cb\u7684\u8eab\u540e\n
\u4e0e\u524d\u671f\u56fe\u50cf\u7406\u8bba\u7684\u5bf9\u6bd4\uff1a\u5728\u56fe\u50cf\u7406\u8bba\u4e2d\uff0c\u8bed\u8a00\u4ece\u6839\u672c\u4e0a\u662f\u4e00\u79cd\u53cd\u6620\uff1b\u5728\u8bed\u8a00\u6e38\u620f\u8bf4\u4e2d\uff0c\u8bed\u8a00\u9996\u5148\u662f\u4e00\u79cd\u6d3b\u52a8\u3002
\u610f\u4e49\u6765\u6e90\u4e8e\u4f7f\u7528\u3002
\u6211\u4eec\u5173\u5fc3\u201c\u9524\u5b50\u201d\u662f\u4ec0\u4e48\u65f6\uff0c\n\u5173\u5fc3\u7684\u662f\u201c\u4f7f\u7528\u4e00\u628a\u9524\u5b50\u201d\uff0c\n\u800c\u4e0d\u662f\u201c\u9524\u5b50\u610f\u5473\u7740\u2026\u2026\u201d\n\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u4e5f\u6b63\u662f\u4ece\u201c\u4f7f\u7528\u4e00\u628a\u9524\u5b50\u201d\u6765\u5b9a\u4e49\u9524\u5b50\n
\u5982\u4f55\u533a\u5206\u201c\u4f7f\u7528\u201d\u201c\u6709\u7528\u201d\u201c\u5229\u7528\u201d\uff1f\n\u5728\u4e00\u4e9b\u60c5\u5883\u4e2d\u80fd\u7528\uff0c\u5728\u4e00\u4e9b\u60c5\u5883\u4e2d\u4e0d\u80fd\u7528\u3002\n
\u8bed\u8a00\u6e38\u620f\u7684\u7c7b\u522b
\u5bb6\u65cf\u76f8\u4f3c\u7406\u8bba\uff08Familien\u00e4hnlichkeiten\uff09
\u201c\u4e00\u4e2a\u5bb6\u65cf\u7684\u6709\u4e9b\u6210\u5458\u6709\u4e00\u6837\u7684\u9f3b\u5b50\uff0c\u53e6\u4e00\u4e9b\u6709\u4e00\u6837\u7684\u7709\u6bdb\uff0c\u8fd8\u6709\u4e00\u4e9b\u6709\u4e00\u6837\u7684\u6b65\u6001\uff1b\u8fd9\u4e9b\u76f8\u4f3c\u4e4b\u5904\u4ea4\u53c9\u91cd\u53e0\u3002\u201c
\u5185\u6db5\uff1a\u4e00\u4e2a\u6982\u5ff5\u7684\u5b9a\u4e49
\u5916\u5ef6\uff1a\u4e00\u4e2a\u6982\u5ff5\u5305\u542b\u7684\u4e0b\u5c5e\u6982\u5ff5\u7684\u8303\u56f4
\u901a\u540d\u7684\u4e0b\u5c5e\u8bcd\uff0c\u5404\u79cd\u4e13\u540d\u4e4b\u95f4\u5e76\u6ca1\u6709\u4e25\u683c\u7684\u754c\u9650\uff0c\u4e00\u4e2a\u76f8\u4f3c\u53e6\u4e00\u4e2a\uff0c\u5206\u4eab\u4e0d\u540c\u7684\u5171\u540c\u7279\u5f81\u3002
\u751f\u6d3b\u5f62\u5f0f\uff08Lebens Form\uff09\uff1a\u5e38\u8bc6\u7684\u91cd\u8981\u6027
\u201c\u626b\u5e1a\u5728\u90a3\u91cc\u201d\u5df2\u7ecf\u8db3\u591f\u6e05\u6670\u3002\n\u201c\u626b\u5e1a\u628a\u548c\u626b\u5e1a\u5934\u5728\u90a3\u91cc\u201d\uff0c\u867d\u7136\u5206\u6790\u5f97\u66f4\u6e05\u695a\uff0c\u4f46\u5728\u4ea4\u9645\u4e2d\u8ba9\u4eba\u8d39\u89e3\u3002\n
\u4eff\u4f5b\u6211\u4eec\u53ea\u8981\u66f4\u591a\u8bf4\u4e00\u70b9\uff0c\u591a\u5206\u6790\u4e00\u70b9\uff0c\u4e8b\u60c5\u5c31\u4f1a\u66f4\u6e05\u695a\uff0c\u4eff\u4f5b\u6ca1\u6709\u4e00\u53e5\u8bdd\u672c\u8eab\u5c31\u662f\u8db3\u591f\u6e05\u695a\u7684\u3002
"},{"location":"Ling/pol_zh/#conclusion-of-agreements","title":"Conclusion of Agreements","text":"\u963f\u4f69\u5c14\u603b\u7ed3\u897f\u65b9\u54f2\u5b66\u7684\u53d1\u5c55\uff1a
\u53e4\u4ee3\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u672c\u4f53\u8bba\uff0c\u4ece\u8fd1\u4ee3\u5f00\u59cb\uff0c\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u8ba4\u8bc6\u8bba\uff0c\u523020\u4e16\u7eaa\uff0c\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u8bed\u8a00\u3002
\u672c\u4f53\u8bba\u7684\u95ee\u9898\uff1a\u4ec0\u4e48\u4e1c\u897f\u5b58\u5728\uff0c\u4ec0\u4e48\u662f\u5b9e\u5728\u7684\u57fa\u672c\u5b58\u5728\u5f62\u5f0f\u3002
\u8ba4\u8bc6\u8bba\u7684\u95ee\u9898\uff1a\u54ea\u4e9b\u4e1c\u897f\u662f\u6211\u4eec\u80fd\u8ba4\u8bc6\u7684\uff0c\u6211\u4eec\u662f\u600e\u6837\u8ba4\u8bc6\u8fd9\u4e9b\u4e1c\u897f\u7684\u3002
\u8bed\u8a00\u7684\u95ee\u9898\uff1a\u6211\u4eec\u5728\u4f55\u79cd\u610f\u4e49\u4e0a\u80fd\u591f\u8ba4\u8bc6\u5b58\u5728\u2014\u2014\u800c\u610f\u4e49\u7684\u9996\u8981\u8f7d\u4f53\u662f\u8bed\u8a00\u3002\u2192 Linguistic Turn
PoL\u7684\u5176\u5b83topic\uff1a 1. \u6307\u79f0\u4e0e\u5b9e\u4f53\uff0c\u8bed\u8a00\u4e0e\u610f\u4e49\u7684\u5173\u7cfb 2. \u901a\u540d\u4e0e\u4e13\u540d\uff0c\u8bcd\u4e49\u7684\u8303\u56f4 3. \u771f\u7406\u7406\u8bba 4. \u300a\u6211\u4eec\u8d56\u4ee5\u751f\u5b58\u7684\u9690\u55bb\u300b\uff1a\u9690\u55bb\u65e0\u5904\u4e0d\u5728\uff0c\u4e0d\u4ec5\u5b9a\u4e49\u4e2d\u7684\u201cxx\u662fxx\u201d\u662f\u9690\u55bb\uff0c\u6709\u65f6\u5355\u4e2a\u8bcd\u5c31\u662f\u4e00\u4e2a\u9690\u55bb\u3002
\u52a8\u8bcd\u662f\u9690\u55bb
\u65f6\u95f4\u5728\u6d41\u901d\u3002\n
\u4ecb\u8bcd\u662f\u9690\u55bb
I\u2019m feeling up today.\nHe is down.\n\u9ad8\u5174\u4e3a\u4e0a\uff0c\u60b2\u4f24\u4e3a\u4e0b\u3002\nWake up.\nHe fell asleep.\n\u6709\u610f\u8bc6\u4e3a\u4e0a\uff0c\u65e0\u610f\u8bc6\u4e3a\u4e0b\u3002\nHe fell ill.\nShe dropped dead.\n\u5065\u5eb7\u548c\u751f\u547d\u4e3a\u4e0a\uff0c\u75be\u75c5\u548c\u6b7b\u4ea1\u4e3a\u4e0b\u3002\nI have controlled over her.\nHe fell from power.\n\u63a7\u5236\u6216\u5f3a\u8feb\u4e3a\u4e0a\uff0c\u88ab\u63a7\u5236\u6216\u88ab\u5f3a\u8feb\u4e3a\u4e0b\u3002\nMy income rose last year.\nThe number of errors is low.\n\u66f4\u591a\u4e3a\u4e0a\uff0c\u66f4\u5c11\u4e3a\u4e0b\u3002\n
\u4e54\u59c6\u65af\u57fa\uff1a
\u7ed3\u6784\u4e3b\u4e49\u8bed\u8a00\u5b66\u5230\u8f6c\u6362\u751f\u6210\u8bed\u6cd5\u3002
\u8bed\u8a00\u5b66\u7684\u5de5\u4f5c\u4e0d\u5e94\u5f53\u662f\u641c\u96c6\u8bed\u8a00\u7d20\u6750\u52a0\u4ee5\u5f52\u7eb3\uff0c\u800c\u662f\u8981\u89e3\u91ca\u8bed\u8a00\u7684\u521b\u9020\u6027\u3002
CNF
S -> AB\nA -> AA | a\nB -> b | e\n
\u8f6c\u6362\u751f\u6210\u8bed\u6cd5\u89c4\u5219 \\(\\Sigma = \\{NP, Vp, T, N, Npsing, NPpl, Aux, V, C, M, En, S, Past, Af\\}\\)
S -> NP + VP\nVP -> Verb + NP\nNP -> Det + N\nVerb -> Aux + V\nDet -> the, a...\nN -> man, ball...\nAux -> will, can...\nV -> hit, see...\n
\u4f20\u7edf\uff08\u6210\u5206\uff09\u8bed\u6cd5\u89c4\u5219
1. \u4e3b + \u8c13\n2. \u4e3b + \u8c13 + \u5bbe\n3. \u4e3b + \u7cfb + \u8868\n4. \u4e3b + \u8c13 + \u5bbe + \u53cc\u5bbe\n5. \u4e3b + \u8c13 + \u5bbe + \u5bbe\u8865\n6. \u4e3b + \u8c13 + \u5e76\u5217\u5bbe\n\n...\n
\u300a\u53e5\u6cd5\u7ed3\u6784\u300b\uff081957\uff09\u6838\u5fc3\u53e5\u548c\u8f6c\u6362\u6982\u5ff5\u3002
\u751f\u6210\u6b65\u9aa4 1. \u751f\u6210\u6838\u5fc3\u53e5\u3002
S -> X1 | X2 | ... Xn\n
\u8f6c\u6362\u7ed3\u6784\uff08\u66ff\u6362\u3001\u7701\u7565\u3001\u6dfb\u52a0\u3001\u6362\u4f4d\uff09\u3002
X1 -> Y1Z1 | ...\n...\n
\u6dfb\u52a0\u5f62\u6001\u97f3\u4f4d\u89c4\u5219\u3002
Z1 -> W1\n...\nZn -> Wn\n
\u8f6c\u6362\uff1a\u6574\u4e2a\u8f6c\u6362\u751f\u6210\u8fc7\u7a0b\u53ef\u4ee5\u5206\u4e3a\u4e09\u4e2a\u6b65\u9aa4
\u6df1\u5c42\u7ed3\u6784\u548c\u8868\u5c42\u7ed3\u6784
\u4e54\u59c6\u65af\u57fa\u8bed\u6cd5\u4f53\u7cfb\u4e2d\uff0c\u6307\u53e5\u5b50\u751f\u6210\u8fc7\u7a0b\u4e2d\u7279\u5b9a\u9636\u6bb5\u6240\u91c7\u7528\u7684\u4e00\u79cd\u7279\u6b8a\u64cd\u4f5c\u624b\u6bb5\u6216\u89c4\u5219\u3002\u6df1\u5c42\u7ed3\u6784\u662f\u5b83\u7684\u8f93\u5165\uff0c\u8868\u5c42\u7ed3\u6784\u662f\u5b83\u7684\u8f93\u51fa\u3002
\u6709\u7684\u53e5\u5b50\u8868\u5c42\u7ed3\u6784\u4e0d\u540c\uff0c\u6df1\u5c42\u7ed3\u6784\u76f8\u4f3c\u3002\u901a\u8fc7\u8f6c\u6362\u64cd\u4f5c\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002
\u6709\u7684\u53e5\u5b50\u6df1\u5c42\u7ed3\u6784\u4e0d\u540c\uff0c\u8868\u5c42\u7ed3\u6784\u76f8\u4f3c\u3002\u901a\u8fc7\u8f6c\u6362\u64cd\u4f5c\u4e0d\u80fd\u76f8\u4e92\u8f6c\u5316\u3002
\u4e3a\u4ec0\u4e48\u4eca\u5929\u6211\u4eec\u8981\u8c08\u8bed\u8a00\u54f2\u5b66\uff1f
\u9648\u5609\u6620\u8001\u5e08\uff1a\u79d1\u5b66\u662f\u4e00\u4e2a\u4e25\u5bc6\u7684\u6574\u6d01\u7684\u4f53\u7cfb\uff0c\u539f\u56e0\u662f\u5b83\u628a\u6240\u6709\u6df7\u6c8c\u7684\u65e0\u6cd5\u89e3\u51b3\u7684\u95ee\u9898\u629b\u5728\u4e86\u8fd9\u4e2a\u4f53\u7cfb\u4e4b\u5916\u3002[\u300a\u8d70\u51fa\u552f\u4e00\u771f\u7406\u89c2\u300b\uff0c2020]
\u6240\u4ee5\u54f2\u5b66\u7684\u95ee\u9898\u662f\u7814\u7a76\u88ab\u79d1\u5b66\u6254\u51fa\u53bb\u7684\u6df7\u6c8c\u3002
\u8bed\u8a00\u54f2\u5b66\u5c31\u50cf\u201c\u5165\u4fb5\u7684\u5b9e\u5728\u754c\u201d\uff0c\u201c\u8fb9\u754c\u7684\u6d4b\u8bd5\u70b9\u201d\u3002
"},{"location":"Ling/pol_zh/#recommended-reading","title":"Recommended Reading","text":"\u300a\u8bed\u8a00\u54f2\u5b66\u300b\u9648\u5609\u6620
\u300a\u666e\u901a\u8bed\u8a00\u5b66\u300b\u7d22\u7eea\u5c14
\u300a\u903b\u8f91\u54f2\u5b66\u8bba\u300b\u7ef4\u7279\u6839\u65af\u5766
\u300a\u54f2\u5b66\u7814\u7a76\u300b\u7ef4\u7279\u6839\u65af\u5766
\u300a\u6211\u4eec\u8d56\u4ee5\u751f\u5b58\u7684\u9690\u55bb\u300b\u4e54\u6cbb\u00b7\u83b1\u8003\u592b
\u300a\u5fc3\u667a\u3001\u8bed\u8a00\u548c\u673a\u5668\u300b\u5f90\u82f1\u747e
"},{"location":"Ling/pol_zh/#_1","title":"\u8ba8\u8bba","text":"\u662f\u5426\u6240\u6709\u6ca1\u6709\u7528\u8bed\u8a00\u8868\u8fbe\u7684\u77e5\u8bc6\uff0c\u90fd\u53ef\u4ee5\u88ab\u7528\u8bed\u8a00\u8868\u8fbe\uff1f\uff08not NP or NP-hard\uff09
\u53ea\u5b66\u4e60\u8bed\u8a00\u662f\u5426\u80fd\u6a21\u62df\u4eba\u7684\u667a\u80fd\u6c34\u5e73\uff1f
\u6a21\u578b\u662f\u5426\u9700\u8981\u5e94\u5bf9\u6240\u6709\u7684\u5f02\u5e38\u60c5\u51b5/\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u672c\u8eab\u8981\u4e0e\u4eba\u7c7b\u8bed\u8a00\u6709\u6240\u533a\u522b
"},{"location":"Ling/Phonetics/reduction/","title":"Reduction of Intentionalverb+prep.
","text":""},{"location":"Ling/Phonetics/reduction/#introduction","title":"Introduction","text":"We will introduce the reductions of \u201cwanna\u201d, \u201cgonna\u201d, \u201cgotta\u201d, explain their reasons and provide a in several AmE dialects. Our inspiration for choosing this topic is from our watching television programs. Thus we will first show several pieces of video clips to get you familiar about our topic.
An interesting fact of this phenomenon: It is focused in bias analysis in hate speech detection task. A reduced form is 20%~30% more likely to be classified as hate speech as it is considered more related to African American English. [9]
"},{"location":"Ling/Phonetics/reduction/#video-clip-examples","title":"Video Clip Examples\u2b50","text":""},{"location":"Ling/Phonetics/reduction/#theory","title":"Theory","text":"In the following section, we will give a theoretical analysis of the phenomenon we found.
"},{"location":"Ling/Phonetics/reduction/#relevant-studies","title":"Relevant Studies","text":"[1]Patterns of Function Words Reduction
[2]Wanna Contraction and prosodic boundary\u2b50
Method: Case study
sentense-final postion: strong form.
a. I want to (wanna) dance//with somebody.5 \nb. I don\u2018t want to (*wanna)//.\n
\u201cwanna\u201d contraction to be one way of disambiguating the sentence
[3]Multiple Spell-Out and Contraction at the Syntax-Phonology Interface
[4]Frequency and Category Factors in the Reduction and Assimilation of Function Words: EPG and Acoustic Measures
[5]Reduction of English Function Words in Switchboard
[6]From Reduction to Emancipation: Is \u201cgonna\u201d A Word?\u2b50
P.133
Corpus Perspectives on Patterns of Lexis
[7]Communicative efficiency and the Principle of No Synonymy: predictability effects and the variation of want to and wanna
Variables:
[8]Some Informal Contractions in American English
\u5199\u5f97\u4e0d\u662f\u5f88\u597d
[9]Exploring the Role of Grammar and Word Choice in Bias Toward African American English (AAE) in Hate Speech Classification, Diyi Yang
In this section, a corpus analysis is carried out to confirm the theories in the literature.
\u600e\u4e48\u542c\uff1a\u7528\u7b2c\u4e09\u4e2ainternational dialect\u8fd9\u4e2a\u5e93\u3002\u91cc\u9762\u53ef\u4ee5\u9009\u62e9African, North American, South American\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u53c8\u6709\u5730\u57df\u4e4b\u5206\u3002\u91cc\u9762\u90fd\u6709transcription\uff0c\u76f4\u63a5\u641c\u7d22\u6709\u6ca1\u6709\u8fd9\u4e09\u4e2a\u8bcd\u7ec4\uff0c\u6709\u5c31\u5b9a\u4f4d\u542c\u4e00\u4e0b\u3002
\u53ef\u80fd\u4e0d\u80fd\u627e\u9f50\u6240\u6709\u53d8\u91cf\uff0c\u6211\u81ea\u5df1\u542c\u7684\u65f6\u5019\u89c9\u5f97\u662f\u5f88\u5c11\u7684\uff0c\u80fd\u627e\u5230\u591a\u5c11\u7b97\u591a\u5c11\u597d\u4e86\u3002
"},{"location":"Ling/Phonetics/reduction/#relevant-corpus-resources","title":"Relevant Corpus Resources","text":"Common Voice
Iterating Dataset Access on Common Voice
People\u2019s Speech\u2b50
MLCommons/peoples_speech \u00b7 Datasets at Hugging Face
International Dialects\u2b50
Accents and Dialects of England | IDEA: International Dialects of English Archive
(a dataset in Kaggle)
openSLR
openslr.org
Stanford CS22S
CS224S: Spoken Language Processing
\u6bcf\u4e2a\u8bb0\u5f55\u4e00\u4e2a\u6bd4\u503c\uff1a#reduction/#\u542c\u4e86\u7684\u53e5\u5b50\u3002\u6bcf\u4e2a\u53d8\u91cf10\uff5e15\u6761\u5373\u53ef\uff0c\u8fd93\u4e2a\u77ed\u8bed\u51fa\u73b0\u4e00\u6b21\u7b97\u4e00\u6761\uff0c\u4e0d\u662f\u4e00\u4eba\u7b97\u4e00\u6761
General Pattern\u2b50
\u53bb\u542c\u4e94\u79cd\u60c5\u51b5
African\u7684\u5728\u5e93\u91cc\u6bd4\u8f83\u5c11
\u5206\u6210\u7537\u5973\u53bb\u542c\uff0c\u671f\u671b#reduction in \u7537>\u5973
\u5f53\u58f0\u5e26\u5904\u4e8e\u6536\u7d27\u72b6\u6001\uff0c\u6d41\u7ecf\u7684\u6c14\u6d41\u4f7f\u58f0\u5e26\u632f\u52a8\uff0c\u8fd9\u65f6\u4ea7\u751f\u7684\u97f3\u662f\u6d4a\u97f3\uff08voiced sound\uff09\uff1b\u5f53\u58f0\u5e26\u5904\u4e8e\u653e\u677e\u72b6\u6001\uff0c\u4e0d\u4f34\u6709\u58f0\u5e26\u632f\u52a8\u7684\u97f3\uff0c\u79f0\u4e3a\u6e05\u97f3\uff08unvoiced sound\uff09\u3002
"},{"location":"Ling/Phonetics/signal/#_2","title":"\u6fc0\u52b1\u6e90\u4e0e\u6ee4\u6ce2\u5668","text":"\u6c14\u6d41\u4e0e\u58f0\u95e8\u662f\u6fc0\u52b1\u6e90\uff0c\u58f0\u9053\u662f\u6ee4\u6ce2\u5668\u3002
"},{"location":"Ling/Phonetics/signal/#_3","title":"\u5171\u632f\u5cf0","text":"\u58f0\u95e8\u7684\u8d28\u91cf\u51b3\u5b9a\u57fa\u97f3\u9891\u7387\uff0c\u57fa\u9891\u7684\u9ad8\u4f4e\u4e5f\u4e0e\u6027\u522b\u548c\u5e74\u9f84\u76f8\u5173\u3002\u7537\u6027\u5927\u7ea6\u572860\uff5e200hz\u3002\u5973\u6027\u548c\u513f\u7ae5\u5927\u7ea6\u5728200\uff5e450hz\u3002
\u4eba\u7684\u53d1\u58f0\u5668\u5b98\uff08\u58f0\u9053\u548c\u53e3\u8154\uff09\u808c\u8089\u8f83\u8f6f\uff0c\u963b\u5c3c\u8f83\u5927\uff0c\u4f1a\u5bf9\u8f83\u591a\u7684\u9891\u7387\u4ea7\u751f\u5171\u9e23\u3002\u628a\u58f0\u9053\u5f53\u4f5c\u4e00\u4e2a\u53d1\u97f3\u7684\u8c10\u632f\u8154\u4f53\u6765\u770b\uff0c\u5f53\u53d1\u97f3\u7684\u6fc0\u52b1\u9891\u7387\u7b49\u4e8e\u58f0\u9053\u7684\u8c10\u632f\u9891\u7387\u65f6\uff0c\u5373\u4e24\u4e2a\u9891\u7387\u76f8\u7b49\uff0c\u58f0\u9053\u5c31\u4f1a\u4ee5\u6700\u5927\u7684\u632f\u5e45\u6765\u56de\u9707\u8361\uff0c\u4e5f\u5c31\u662f\u5171\u9e23\u3002\u5171\u9e23\u5f15\u8d77\u4e86\u8c10\u632f\u8154\u632f\u52a8\uff0c\u63a5\u7740\u58f0\u9053\u5c31\u653e\u5927\u4e86\u67d0\u4e9b\u9891\u7387\u6210\u5206\uff0c\u5e76\u8870\u51cf\u5176\u5b83\u9891\u7387\u6210\u5206\uff0c\u4ece\u800c\u4ea7\u751f\u67d0\u4e9b\u8c10\u632f\u9891\u7387\uff0c\u5728\u9891\u7387\u7279\u6027\u4e0a\u88ab\u653e\u5927\u7684\u8c10\u632f\u9891\u7387\u5c31\u4f1a\u9646\u7eed\u5cf0\u8d77\uff0c\u4e00\u822c\u628a\u8fd9\u4e9b\u5171\u632f\u9891\u7387\u79f0\u4e3a\u5171\u632f\u9891\u7387\uff0c\u5cf0\u79f0\u4e3aformant\u3002
\u5173\u4e8e\u5171\u632f\u9891\u7387\u7684\u5927\u5c0f\uff0c\u56e0\u4e3a\u53e3\u8154\u548c\u58f0\u9053\u53ef\u4ee5\u7ec4\u5408\u6210\u5404\u79cd\u5f62\u72b6\u548c\u5c3a\u5bf8\uff0c\u6240\u4ee5\u58f0\u9053\u6709\u4e0d\u540c\u7684\u5171\u632f\u9891\u7387\u3002
\u5173\u4e8e\u5171\u632f\u9891\u7387\u7684\u8bed\u4e49\uff0c\u7531\u4e8e\u6d4a\u97f3\u548c\u5143\u97f3\u662f\u58f0\u5e26\u632f\u52a8\u4ea7\u751f\u7684\uff0c\u6240\u4ee5\u4e00\u822c\u8ba4\u4e3a\u5171\u632f\u5cf0\u4e0e\u6d4a\u97f3\u548c\u5143\u97f3\u5bc6\u5207\u76f8\u5173\u3002
\u7406\u60f3\u58f0\u9053\u6a21\u578b
\u4e0b\u9762\u56fe\u662f\u4e3b\u8981\u5143\u97f3\u548c\u7b2c\u4e00\u4e8c\u5171\u632f\u5cf0\u7684\u9891\u7387\u5bf9\u5e94\u56fe\u3002
\u4e09\u4e2a\u5143\u97f3\u548c\u5171\u632f\u5cf0\u7684\u5bf9\u5e94\u5173\u7cfb\u5982\u4e0b\u3002\u4e00\u4e2a\u97f3\u7d20\u53ef\u4ee5\u7528\u4e09\u4e2a\u5171\u632f\u5cf0\u8868\u793a\uff0c\u6bcf\u4e2a\u5171\u632f\u5cf0\u7684\u9891\u8c31\u7279\u6027\u90fd\u53ef\u4ee5\u7528\u4e00\u4e2aGMM\u6765\u5efa\u6a21\u62df\u5408\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e09\u4e2aGMM\u53ef\u4ee5\u5efa\u6a21\u62df\u5408\u4e00\u4e2a\u97f3\u7d20\uff0c\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48HMM\u9700\u8981\u4e09\u4e2a\u72b6\u6001\u3002\u800c\u4e00\u822c\u5b9e\u9645\u4e2d\u6211\u4eec\u7528\u4e94\u4e2aHMM\u72b6\u6001\uff0c\u56e0\u4e3a\u6e05\u97f3\uff08\u975e\u6587\u672c\u56e0\u7d20\uff09\u6bd4\u8f83\u590d\u6742\uff0c\u9700\u8981\u4e94\u4e2a\u5171\u632f\u5cf0\u624d\u80fd\u8f83\u597d\u8868\u793a\u3002
\u4e8b\u5b9e\u4e2d\u7684\u95ee\u9898\u6ca1\u6709\u8fd9\u4e48\u7b80\u5355\uff0c\u5982\u679c\u8003\u8651\u53d8\u65f6\uff0c\u5f53\u5f62\u6210\u4e00\u4e2a\u8bcd\u8bed\u65f6\uff0c\u6bcf\u4e2a\u97f3\u7d20\u603b\u4f1a\u4e0e\u524d\u540e\u7684\u97f3\u7d20\u5173\u8054\uff0c\u79f0\u4e3a\u534f\u540c\u53d1\u97f3\u3002\u7531\u4e8e\u534f\u540c\u53d1\u97f3\u7684\u4f5c\u7528\uff0c\u524d\u540e\u4e24\u4e2a\u5171\u632f\u5cf0\u53ef\u80fd\u4f1a\u91cd\u53e0\u6216\u8005\u9760\u8fd1\uff0c\u6216\u8005\u76f8\u4e92\u4f5c\u7528\uff0c\u6b64\u65f6\u5f88\u96be\u8bf4\u4e09\u4e2a\u5171\u632f\u5cf0\u8868\u793a\u4e00\u4e2a\u72ec\u7acb\u7684\u5143\u97f3\uff0c\u8fd9\u4e09\u4e2a\u5171\u632f\u5cf0\u53ef\u80fd\u4f1a\u5e26\u6709\u522b\u7684\u524d\u540e\u97f3\u7d20\u9891\u8c31\u7279\u6027\u5728\u5176\u4e2d\u3002
"},{"location":"Ling/Phonetics/signal/#spectrogram-spectral-waterfall-voice-print","title":"\u8bed\u8c31\u56fe(spectrogram, spectral waterfall, voice-print)","text":"\u8bed\u8c31\u56fe\u6709\u4e09\u4e2a\u7ef4\u5ea6\uff1ax\u8f74\u65f6\u95f4\uff0cy\u8f74\u9891\u7387\uff0cz\u8f74\u8f90\u503c\u3002
"},{"location":"Ling/Phonetics/signal/#_4","title":"\u5143\u97f3\u548c\u8f85\u97f3\u7684\u8bed/\u9891\u8c31\u56fe\u7279\u5f81","text":"\u5143\u97f3\u7684\u8bed\u8c31\u56fe\u5dee\u5f02
f3\u6700\u660e\u663e\u7684\u4f53\u73b0\u662f\u5728\u8f85\u97f3/r/\u4e2d\uff0cf3\u660e\u663e\u4f4e
\u8f85\u97f3\u7684\u8bed\u8c31\u56fe\u5dee\u5f02 \u533a\u5206voiced\u548cvoiceless
four acoustic properties of plosives
\u7b2c\u56db\u7ae0\u5143\u8f85\u97f3\u7684\u58f0\u5b66\u77e5\u8bc6\u8fa8\u6790.ppt
Music lab https://esp.mit.edu/download/a29f71f1fddf4f6470eb50726aa98de4/L7357_Phonetics_2hrs_Splash2013.pdf
https://www.mq.edu.au/__data/assets/pdf_file/0009/911646/vowels.pdf
Acoustic structure of consonants
Human Voices and the Wah Pedal
3.2. Acoustic Aspects of Consonants
"},{"location":"Ling/Phonetics/signal/#_5","title":"\u5e38\u7528\u97f3\u9891\u7279\u5f81","text":"\u97f3\u9891\u7279\u5f81\u63d0\u53d6\u2014\u2014\u5e38\u7528\u97f3\u9891\u7279\u5f81 - LeeLIn\u3002 - \u535a\u5ba2\u56ed
\u5f00\u6e90\u9879\u76eeaudioFlux: \u9488\u5bf9\u97f3\u9891\u9886\u57df\u7684\u6df1\u5ea6\u5b66\u4e60\u5de5\u5177\u5e93 - audioFluxLab - \u535a\u5ba2\u56ed
"},{"location":"Ling/Pragmatics/ca_da/","title":"Research Methods: Conversation Analysis and Discourse Analysis","text":""},{"location":"Ling/Pragmatics/ca_da/#discourse-analysis","title":"Discourse Analysis","text":"Some discourse analysis are taught in linguistic departments (Johnstone, 2018)
Foucault (1972, 1980) use 'discourse' to refer to the ways of talking and thinking constitute ideologies (set of interrelated ideas) and serve to circulate power in society, and in the sense involved patterns of belief and habitual actions as well as patterns of language.
Johnstone, Barbara. 2018. Discourse Analysis (3rd ed.). UK: Wiley-Blackwell.
"},{"location":"Ling/Pragmatics/ca_da/#conversational-analysis","title":"Conversational Analysis","text":""},{"location":"Ling/Semantics/","title":"Index","text":""},{"location":"Ling/Semantics/#contents","title":"Contents","text":"1 - Definition Clearification
This chapter provides a brief introduction to the terminologies involved in semantics.\n
2 - Logics & Formal Semantics
This chapter first introduces the semiotics in formal semantics (which adopts a similar system with that in the logics). It then discusses about the semantics in two perspectives: the propositional logic and the predicate logic. It also introduces several basic rules in logic inference.\n
3 - Scope Ambiguity
This chapter discusses on the unsolved questions in scope ambiguity.\n
"},{"location":"Ling/Semantics/#grading","title":"Grading","text":"mid-term: 35%
final: 50%
participation: 15%
"},{"location":"Ling/Semantics/#two-tests","title":"Two tests","text":"Two tests will be given during the term, one in the middle and one at the end of the term, covering all the material covered up to that point in the course. The tests will be a combination of various types of questions, including true/false and short essay.
"},{"location":"Ling/Semantics/#final-review-for-fun","title":"Final Review & For Fun","text":"The following parts are written in preparation for the final review but I upload it as well for you to read for fun.
"},{"location":"Ling/Semantics/#noble-semanticians","title":"Noble Semanticians","text":"Name Field Contribution Live Nation Institution Fun facts Noam Chomsky mainly in syntax generative grammar, transformational grammar, government and binding theory, minimalist program, productivity of language, recursivity of language 1928- USA MIT Most prominent linguist alive Ferdinand de Saussure linguist and semiotician founder of semiotics. concepts: sign, signifier vs. signified, diachronic vs. synchronic, language vs. parole, paradigmatic vs. syntagmatic 1857-1913 Switzerland University of Geneva, Switzerland Charles Sanders Peirce philosopher, mathematician, logician founder of semiotics. concepts: index, icon, symbol. 1839-1914 Milford Pennsylvania JHU Michel Br\u00e9al comparative grammar coined the term \u201csemantics\u201d, diachronic focus 1832-1915 born in Rheinlan (Germany), studied in Paris and Berlin in Paris Leonard Bloomfield structural linguistics structural linguistics, language as a self-regulating system, behaviorism(stimulus-response testing) 1887-1949 Yale University reject introspection Aristotle polymath term logic, initiator of western scientific tradition 384-322 BC Stagira, Greece tutor of Alexander the Great Gottlob Freg philosopher, logician, mathematician predicate logic, sense(sentence\u2019s proposition) vs. reference (its truth value) 1848-1925 German University of Jena extreme right-wing views Peter Geach philosopher, professor of logic donkey sentence (1962) 1916-2013 England Oxford Richard Montegue semanticist Montegue grammar: syntax and semantics go together 1930-1971 student of Alfred Tarski, gay man, killed in his apartment, four influential papers Gareth Evans philosopher philosophy of mind, work on reference, e-type anaphora 1946-1980 England Oxford Irene Heim semanticist definite and indefinite pronouns 1954- German, Munich MIT, phd 1982 advisor: Barbara Partee Hans Kamp philosopher and linguist discourse representation theory (DRT) 1954- Dutch Bertrand Russell philosopher, logician logic, philosophy of mathematician 1872-1970 Wales, Britain Cambridge Henri\u00ebtte de Swart linguist tense and aspect, negation, bare nominals and indefinite noun phrases. She has also investigated the role of semantics in language evolution, and was involved in the development of bidirectional optimality theory. 1961- Dutch director of Netherlands Graduate School of Linguistics and Utrecht Institute of Linguistics"},{"location":"Ling/Semantics/#example-questions","title":"Example questions","text":"What is a donkey pronoun?
A donkey sentence is such that an expected existential is interpreted as universal taking wide scope.\n
What is a discourse pronoun:
outside the scope of existing quantifier\ne.g. No student studies semantics. He is outside.\n
The scope of a quantifier is always bound in the clause it appears.
True\n
What is quantifier raising?
Chmosky and May.\nLF, \n
What are De Morgan\u2019s laws?
~(p or q) <=> (~p) and (~q)\n~(p and q) <=> (~p) or (~q)\n
What are conditional laws
p -> q <=> ~p or q\n
When is the indefinite \u201ca\u201d not an existential quantifier?
1. donkey sentence\n2. generic noun phrase. A woman is difficult to please. \\forall x(Wx -> Dx)\n3. John is a plumber.pj\n
2 readings: Some boy smiled at Jane and some boy kissed Molly.
\\exist x(Bx and Sx,j and Kx,m)\n\\exist x(Bx and Sx,j) and \\forall y(By and Ky,m)\n
2 Types of Recursion
embedding and coordination\n
"},{"location":"Ling/Semantics/ambiguity/","title":"Scope Ambiguity","text":""},{"location":"Ling/Semantics/ambiguity/#scope-ambiguity","title":"Scope Ambiguity","text":""},{"location":"Ling/Semantics/ambiguity/#scope-and-anaphora","title":"Scope and Anaphora","text":"antecedent vs. postcedent
anaphor vs. cataphor
Predicate logic is suited to capture natural language meaning
allow recursion = recursivity
two sources of recursion
some boy kissed every girl.\n\nEvery girl was kissed by some boy.\n
Someone mentioned tehy called everyone.\n\n\\forall x: Px\\forall y(M(x, Cxy))\n
linear order: negative polarity item
graph TD\n DS -.Transformation.-> SS\n SS -.send off.-> PF\n SS -.send off.-> LF\n PF -.acoustic representation.-> SS\n LF -.semantic interpretation.-> SS\n
Transformation:
CALLOUT: annotation, connotation and denotation
annotation
connotation: intension.
A meaning of a word or phrase that is suggested or implied, as opposed to a denotation, or literal meaning. A characteristic of words or phrases, or of the contexts that words and phrases are used in.
The\u00a0connotations\u00a0of the phrase \"you are a dog\" are that you are physically unattractive or morally reprehensible, not that you are a canine.
A technical term in logic used by J. S. Mill and later logicians to refer to the attribute or aggregate of attributes connoted by a term, and contrasted with\u00a0denotation\u00a0.
The two expressions \"the morning star\" and \"the evening star\" have different\u00a0connotations\u00a0but the same denotation (i.e. the planet Venus).
denotation
Quantifier-raising - NC RM - syntactic structure comes before the semantic structure - The movement we make in SS to remove ambiguity in DS is called quantifier-raising. - take the quantifier to the higher position to show the scope
Quantifier-in - Montague grammar - The derivational illustration is called quantifier-in. - each predicate take an argument once a time
Quantifier storage - Cooper storage - semantic ambiguity not represented in syntactic structure - semantic representation in which scope ambiguities are obtained without special syntactic rules
"},{"location":"Ling/Semantics/ambiguity/#quantifier-in","title":"Quantifier-in","text":"interrogative: asking a question
which woman does every man love?\n
which scopes over every.
"},{"location":"Ling/Semantics/ambiguity/#scope-ambiguity_1","title":"Scope ambiguity","text":"e.g. some boy did not laugh.
\\exist x (Boy(x) and ~Laugh(x))\n~\\exist x (Boy(x) and Laugh(x))\n
some boy kissed no girl.
\\exist x (Boy(x) and ~\\exist y (Girl(y) and Kiss(x, y)))\n~\\exist y (Girl(y) and \\exist x (Boy(x) and Kiss(x, y))): there was no girl kissed by a boy\n
every boy kissed no girl.
\\forall x (Boy(x) and ~\\forall y(Girl(y) and Kiss(x, y)))\n
"},{"location":"Ling/Semantics/ambiguity/#deictic","title":"Deictic","text":"No boy said he was hungry.
No boy was present. He was outside instead.: \u201che\u201d is trying to refer to \u201dno boy\u201d but outside the scope.
pronoun \\(\\sub\\) anaphora
"},{"location":"Ling/Semantics/ambiguity/#discourse-anaphora","title":"Discourse Anaphora","text":"e.g.
Every student was present and she was interested.\n
every: scopes over \u201cEvery student was present\u201d
every: an indefinite quantifier. \u201cshe\u201d\u2019s antecedent is not clear
\u201cshe\u201d is hardly bound by the antecedent. \u201cshe\u201d is free * ungrammatical: \u4e0d\u5408\u8bed\u6cd5\u7684, syntactic
"},{"location":"Ling/Semantics/ambiguity/#infelicitous-semantic-fit-the-context","title":"infelicitous: \u4e0d\u5408\u9002\u7684, semantic, fit the context","text":"discourse pronoun: in separate clauses
sentence quantifier:
Some boy said he was hungry.\nNo boy said he was hungry.\n
discourse quantifier:
Some boy was present; he was hungry.\n#No boy was present; he was hungry. // he is free\n
coreference individual constants
Fred thought he was the the best\n
binding individual variables
Every student thinks he/she is the best\n
So we may conclude the following rules for e-type anaphora. BUT this part has NOT been verified with any authority. Do NOT take them as given truths during exams.
e.g. No boy thinks that he has a chance.
~\\exist x(Boy(x) and Think(x, Has-a-chance(x)))\n
A particular boy said he wanted to kiss every girl. He then did it.
\\exist !x(Bx and W(x, K(x, \\forall y(Gy -> K(x, y))))) and K(x, y)\n
"},{"location":"Ling/Semantics/ambiguity/#donkey-anaphora","title":"Donkey anaphora","text":"if a farmer owns a donkey, he beats it.
* \\exist x (Fx and \\exist y (Dy and O(x, y))) -> B(x, y)\n\\forall x \\forall y (Fx and Dy and O(x, y) -> B(x, y))\n
= every farmer who owns a donkey beats it.
\\exist x(Fx and \\exist y (Dy and O(x, y)) -> B(x, y)) // y is free\n
\u2757\u2757\u2757
A donkey sentence is such that an expected existential is interpreted as universal taking wide scope.
donkey pronoun can be: it, him, they (can also be plural forms)
\u201ca\u201d: generic indefinite
A woman is a difficult thing to please.\n
[Every farmer [who owns a donkey] beats it.]
universal wide scope: it scopes more over the relative clause
The problem - Existential with narrow scope - interpreted as universal with wide scope - in conditional clauses - in restriction of every
Conclusion - the machinery of predicate logic is broken - cannot capture meaning of natural language
If a student tries, she passes the exam.
(\\exist x(Sx and Tx)) -> Py ; y is free\n\\exist x((Sx and Tx)) -> Py)\n
interpretation
\\forall x((Sx and Tx) -> px)\n
Solutions for donkey anaphora:
E-type anaphora
initial examples
A student came in. She had a question about the exam.\nshe = the student came in\n\nBill owns some sheep and Max vaccinates them.\nthem = the sheep Bill owns. E-type pronoun, some sheep scopes over the first half\n
If a student likes Copenhagen, she is happy.
she = for every case we examine, the student is \n
every student who reads a semantic paper likes it.
Bill owns a cat. Max takes care of it.\nBill is a cat-owner. #Max takes care of it.\n
DRT (Dynamic binding theory)
Unselective binding example of the subject is \u2018unselectively bound\u2019 by a special \u2018generic operator.
Dogs bark.\nA dog barks.\n
Reference: Unselective Binding
"},{"location":"Ling/Semantics/ambiguity/#chapter-6-in-short-discoursedonkey-anaphora","title":"Chapter 6 in short: Discourse/Donkey Anaphora","text":"(\u52a0\u7c97\u7684\u662fDonkey anaphora\u548cE-type anaphora\u7684\u533a\u522b)
Discourse: basic unit of interpretation
Donkey sentence: is such that an expected existential is interpreted as universal taking wide scope. / sentences that contain a pronoun with clear meaning but whose syntactical role in the sentence poses challenges to grammarians (wikipedia)
e.g.
every farmer who owns a donkey beats *it*.\nit: (corresponding to the) existential (\"a\") but interpreted as universal\n
every police officer who arrested a murder insulted *him*.\nhim\n
every farmer who owns some sheep cleans *them*.\nthem\n
donkey anaphora = donkey pronoun: it, him, they (can also be plural forms)
Analysis of donkey anaphora: Montague grammar
e.g.
\\forall x(Farmer(x) and \\exist y (Donkey(y) and Owns(x,y)) -> Beat(x,y))\n
Anaphoric relations in sentence and discourse - E-type anaphora: pronoun outside the scope of binder, not bound, content of pronoun reconstructed, reconstruction based on context - in separate sentences
```\n A student came in. *She*(the student came in) had a question about the exam.\n ```\n\n- in the same sentence but outside the scope\n ```\n If a student likes Copenhagen, *she*(for every case we examine, the student in question who likes Copenhagen) is happy.\n ```\n\n- problem of compound: antecedent must appear as a noun?\n ```\n Bill owns a cat. Max takes care of it.\n Bill is a cat-owner. # Max takes care of it.\n ```\n
Anaphora resolution - TODO
"},{"location":"Ling/Semantics/definitions/","title":"Definition Clarification","text":""},{"location":"Ling/Semantics/definitions/#what-is-semantics","title":"What is semantics?","text":"parenthesis
small dogs and cats: \n- small (dogs and cats)\n- (small dogs) and cats\n\n// example of scope of quantifier\n
logical quantifier
every body did not cry:\n- every not (boy did cry) 'no boy did cry'\n- not every (boy did cry) 'at least one boy did cry'\n
everything but the subject e.g. John likes grammar.
content verb or adjective taking arguments e.g. like (John, grammar).
graph TD\n Language_Ability --> Competence\n Language_Ability --> Performance\n Competence --> Grammar\n Competence --> Lexicon\n Grammar --> Semantics\n Grammar --> Phonology\n Grammar --> Syntax\n Grammar --> Pragmantics\n
"},{"location":"Ling/Semantics/definitions/#semantics-syntax","title":"Semantics & Syntax","text":""},{"location":"Ling/Semantics/definitions/#syntax-needs-semantics","title":"Syntax needs semantics","text":"We can/cannot study syntax without semantics.
Colorless green ideas sleep furiously.\n
Deixis is how objects, events and situations relate to the here and now of the speakers. It shows that utterance meaning cannot be fully determined by sentence meaning.
(Last week) (I) play(ed) tennis with Chris.\n
"},{"location":"Ling/Semantics/definitions/#deictic-vs-anaphoric-use-of-pronouns","title":"Deictic vs. Anaphoric use of pronouns","text":"Deictic: pointing context Anaphoric: linguistic expression context. pronoun resolution: antecedent - pronoun
\ud83d\udcad index - indices (higher register) / indexes \ud83d\udcad Desiderata (high-register way to say Goal, desideratum. sl.)"},{"location":"Ling/Semantics/definitions/#map-of-semantics-taxomony","title":"Map of Semantics / Taxomony","text":"Semantics - lexical semantics - meaning of lexical items - smaller unites - mainly words - morphemes - compositional semantics - meaning of larger units - phrases and sentences - word combination
"},{"location":"Ling/Semantics/definitions/#utterance-sentence-proposition","title":"Utterance / Sentence / Proposition","text":"abiguity: bank, punch, pitcher\nsynonymy: beautiful-lovely, antonymy: male-female\nhyponymy: set -> superset\ntaxonomy: set -> subset\nsymmetric relation: marry. mutually entail each other\nconverse relation: send, sell\nmeronomy:
"},{"location":"Ling/Semantics/definitions/#1-homonymy","title":"1) homonymy","text":"part-whole relationship
subtypes of meronymy
pistachio - almond taxonymy\nlaugh - cry move in - move out\ncry - weep\nRMB - monetary unit\ngrilfriend - wife\nsit - stand\njump - hop\ngood - bad\nbeat - beet\nrise - fall reverse\ncigarette - cigar taxonymy\nkid - goat dragon - monster\n
"},{"location":"Ling/Semantics/definitions/#compositional-semantics","title":"Compositional semantics","text":"Michel Br\u00e9al: coined semantics
Ferdinand de Saussure: semiotician, diachronic vs. synchronic.
Leonard Bloomfield: structural linguistics, Language, behaviorism(stimulus-response testing). reject introspection(theorize about language learning by thinking about on ones own experience)
"},{"location":"Ling/Semantics/definitions/#diachronic-synchronic","title":"Diachronic & Synchronic","text":"Noam Chomsky Syntax
"},{"location":"Ling/Semantics/definitions/#generative-grammar","title":"Generative Grammar","text":"e.g. Flying planes can be dangerous.
graph TD\n are --> planes\n planes --> flying\n are --> dangerous\n
graph TD\n is --> flying\n flying --> planes\n is --> dangerous\n
"},{"location":"Ling/Semantics/definitions/#pronoun-resolution","title":"pronoun resolution","text":"anaphora
John said he would helps.\nNo boy said he would help. no boy: all the boy not, not exist a boy\n
coreference(coreferential): refer to same person
notes: cf. compare, e.g. for example
graph TD\n Inference --> Entailment\n Inference --> Presuppositions\n Inference --> Implicature\n
any conclusion drawn from a set of propositions, from something someone has said and so on.
"},{"location":"Ling/Semantics/definitions/#entailment","title":"Entailment","text":"Three girls were present. -> More than two girls were present.\nThree girls were not present. kills More than two girls were present.\n
Cannot be cancelled
# Three girls were present, but actually two girls come.\n#: semantically wrong\n
"},{"location":"Ling/Semantics/definitions/#presupposition","title":"Presupposition","text":"Jim regrets ignoring the first problem. -> Jim has the first problem.\nJim does not regret ignoring the first problem. -> Jim has the first problem.\n
cannot be cancelled
# Jim regrets ignoring the first problem, but he does not have the first problem.\n
"},{"location":"Ling/Semantics/definitions/#implicature","title":"Implicature","text":"Susan blushes when Jim looks at her, but she does not have a crush on him.\n
"},{"location":"Ling/Semantics/definitions/#compositionality","title":"Compositionality","text":"Proposed by Noam Chomsky, the term compositionality entails three dimension.
The meaning of the whole is a function of the meaning of its parts and the way they are put together.: \u2026 is determined by\u2026
"},{"location":"Ling/Semantics/formal_semantics/","title":"Logics & Formal Semantics","text":""},{"location":"Ling/Semantics/formal_semantics/#metalanguage","title":"Metalanguage","text":"a. January has 31 days.\nb. *******January******* has 7 letters.\nb*. 'January' has 7 letters.\n
Liar sentence
(31) Sentence (31) is false.\n
solutions: (\u4e0d\u8003)
fuzzy logic
x = NOT(x)\nx = 1 - x\nx = 0.5\n
Alfred Tarski paradox arises only in languages that are \u201csemantically closed\u201d.
Arthur Prior equivalent
This statement is false.\nThis statement is true and this statement is false.\n
Saul Kripke Whether a sentence is paradoxical or not can be depend upon contingent facts.
A majority of what Jones says about me is false.\n
Smith is a big spender.\nSmith is soft on crime.\nEverything Smith says about me is true.\n
If a statement's truth value is ultimately tied up in some evaluable fact about the world, that statement is \"grounded\". If not, that statement is \"ungrounded\". Ungrounded statements do not have a truth value. Liar statements and liar-like statements are ungrounded, and therefore have no truth value.
Jon Barwise and John Etchemendy \u201cdenial\u201d or \u201cnegation\u201d
Dialetheism
Dialetheism is the view that there are true contradictions. Dialetheism raises its own problems. Chief among these is that since dialetheism recognizes the liar paradox, an intrinsic contradiction, as being true, it must discard the long-recognized\u00a0principle of explosion, which asserts that any proposition can be deduced from a contradiction, unless the dialetheist is willing to accept trivialism \u2013 the view that\u00a0all propositions are true. Since trivialism is an intuitively false view, dialetheists nearly always reject the explosion principle. Logics that reject it are called\u00a0paraconsistent.
Non-cognitivism
logic overview
graph TD\n Logic --> Logic_from_antiquity\n Logic --> Predicate_Logic\n Logic_from_antiquity --> Term_Logic\n Logic_from_antiquity --> Propositional_Logic\n
logic from antiquity: older
predicate logic: newer
Aristotle: term logic
Gottlob Frege: predicate logic
"},{"location":"Ling/Semantics/formal_semantics/#history-of-logics","title":"History of Logics","text":"Not applied for - question (?) - exclamation - modal: modal logic
\ud83d\udcad ergo: therefore"},{"location":"Ling/Semantics/formal_semantics/#term-logic","title":"Term logic","text":""},{"location":"Ling/Semantics/formal_semantics/#modus-ponens","title":"Modus Ponens","text":"Means of putting, MP syllogism, affirming the antecedent
P(conditional statement): If it rain, I do not go to school.\nH: It rains.\nC: I do not go to class.\n
Formal fallacy: affirming the consequent. Abductive reasoning.
P: If it rains, I will not go to class.\nH: I do not go to class.\nC: * It rains.\n
"},{"location":"Ling/Semantics/formal_semantics/#modus-tollens","title":"Modus Tollens","text":"Means of carrying, MT syllogism, denying the consequent.
P: If it has not been cloudy, it does not rain.\nH: It rains.\nC: It has been cloudy.\n
"},{"location":"Ling/Semantics/formal_semantics/#hypothetical-syllogism","title":"Hypothetical syllogism","text":"principle of transitivity
P: If it rains, the soils goes wet. If the soil goes wet, the plants grow.\nH: It rains.\nC: The plants grow.\n
"},{"location":"Ling/Semantics/formal_semantics/#disjunctive-syllogism","title":"Disjunctive syllogism","text":"two premises and a conclusion
P: It either rains or its sunny.\nH: It rains.\nC: It is not sunny.\n
"},{"location":"Ling/Semantics/formal_semantics/#three-types-of-reasoning","title":"Three types of reasoning","text":"Deductive reasoning
general to the particular. based on entailment
Inductive reasoning
particular to the general. empiricism
Abductive reasoning
formal fallacy. All dogs bark, Fido barks, Fido is a dog.
Abductive reasoning allows inferring a as an explanation of b. As a result of this inference, abduction allows the precondition a to be abducted from the consequence b.
Properly used, abductive reasoning can be a useful source of\u00a0priors in\u00a0Bayesian statistics.
John is friendly or John is not friendly.\n
p V_e ~p T T F F T T John is friendly and John is not friendly.\n
p and ~p T F F F F T It is not the case that John is not friendly.\n
~ ~ p T F T F T F contingent.
It is not the case that John is hungry or John is not grumpy.\n
~( p or ~q F T T T F T T F F F T T T F F F"},{"location":"Ling/Semantics/formal_semantics/#material-implication","title":"Material implication \u2192","text":"converse: q\u2192p. affirming the consequent
inverse: ~p\u2192~q. denying the antecedent
contrapositive: ~q\u2192~p. modus tollens
given p\u2192q.
Although it was extremely cold, Sally did not stay indoors.
~q->p\np and ~q\n
We get a holiday, or we protest.
~p->q\np or q\n
Jone said that Jane helped him.
p\np and q\n
John\u2019s sister burped
p: John has a sister. presupposition, assume it true\nq: This sister burped.\np\np and q\n
John arrives before Jane left
p before q\n
John did not arrive before Jane left.
~p before q\np ~before q\n
"},{"location":"Ling/Semantics/formal_semantics/#predication-and-quantification","title":"Predication and Quantification","text":"universal quantifier: every, each, all, any, only
existential quantifier: a, some, there is \\(\\exist\\), for all \\(\\forall\\)
predicate, argument
John may like Sally.
predicate: may like\n
John has a crush on Sally.
predicate: has a crush on\n
Frank is the father of Susan.
predicate: is the father of\n
Frank is Susan\u2019s father.
predicate: is...'s father\n
Adjunct: if, probably, means, of course, early
Valent, empty place holder: formal subject
"},{"location":"Ling/Semantics/formal_semantics/#collective-and-distributive-readings","title":"Collective and distributive readings","text":"Jogn and Molly ate a pizza.\np: one pizza, ate one together. distributive\np and q: two pizzas, each ate a pizza. collective\n
Cinthia and Sam have saved 100 dollars.\np: together 100 dollars\np and q: 200 dollars\n
Content verb is a predicate, but functional verbs are not
John obviously spoke with Jane because he had to.
predicate: spoke with\nargument: John, Jane\nadjuncts: obviously, because he had to.\n
If I get a chance, I will probably try to avoid the mistake.
predicate: will try to \nargument: I, avoid the mistake\nadjuncts: If I get a chance, probably\n
John performed Jill\u2019s operation first.
\n
The person who talk loudly is Jim\u2019s father.
predicate: is someone's father\nargument: the person who talk loudly, Jim\nadjunct: \n
the talking loudly person
predicate: talking\nargument: person\nadjunct: loudly\n
predicate: the nodes that are connected in SUD parsing tree
universal dependency (UD)
syntactic-universal dependency (SUD)
graph TD\n Primitive_units_within_propositions --> Predicates\n Primitive_units_within_propositions --> Arguments\n Arguments --> individuals_Terms\n individuals_Terms --> constants\n individuals_Terms --> variables\n
lexical predicates vs. syntactic predicates
individual constants vs. individual variables
e.g. We think John likes Susan.
T(w, Lj,s)\n
Types of predicates:
e.g. Monica hid her bicycle.
x hide y: Hx,y\nMonica: m\nher bicycle: b\nHm,b\n
e.g. Monica did not hide her bicycle.
x hide y: Hx,y\nMonica: m\nher bicycle: b\n~Hm,b\n
e.g. Monica laughed and cried.
Monica: m\nlaugh: L()\ncry: C()\nLm and Cm\n
e.g. Jim sent Monica his dog.
Sj,m,d\n
e.g. William did not help or hinder Mike.
~ (H1w,m or H2w,m) \n
e.g. Jennifer promise to help.
P(j, Hj)\n
e.g. Jennifer did not promise to help.
~P(j,Hj)\n
e.g. Jennifer promise to not laugh.
P(j,~Lj)\n
e.g. Mike claimed he wanted to help.
C(m, W(m/x, Hm/x))\n\nm: Mike\nx: maybe some other\n
e.g. John asked Mandy to stop laughing.
A(j, m, S(m, Lm))\n
e.g. John and Larry called Molly.
Cj,m and Cl,m\nC(j and l, m)\n
e.g. Molly did not call John and Larry.
~C(m, j) and ~C(m, l)\n~C(m, j and l)\n~C(m, j) or ~C(m, l)\n
entailment: (universal instantiation)
every dog barks \u2192 if something is a dog, then it is a dog.
Universal quantification
\\(\\forall\\)x (Dx \u2192 Bx)
D = (d1, d2, d3,\u2026)
\\(\\forall\\)x (Dx \u2192 Bx)= (Bd1 and Bd2 and Bd3, \u2026.)
Existential quantification
\\(\\exist\\)x (Dx and Bx)
D = (d1, d2, d3,\u2026)
\\(\\exist\\)x (Dx and Bx) = (Bd1 or Bd2 or Bd3, \u2026.)
e.g. Every cat barfed.
\\forall x (Cx -> Bx)\n
e.g. The cat barfed.
Bc\n
e.g. Bill fed cat.
\\forall x (Cx -> Fb,x)\n
e.g. Some dog barked at Fred.
\\exist x (Dx and Bx,f)\n
e.g. Fred scolded some dog.
\\exist x (Dx and Sf,x)\n
e.g. Fred and Susan avoid some dog.
\\exist x (Dx and Af,x and As,x)\n\\exits x (Dx and Af,x) and \\exist y (Dy and Af,s)\n
e.g. No dog barks.
\\forall x (Dx -> ~Bx)\n~\\exist x (Dx and Bx)\n
e.g. Bill fed no dog.
~\\exist x (Dx and Fb,x)\n\\forall x (Dx -> ~Fb,x)\n
e.g. No dog barked at Susan or chased Fred.
~\\exist x ((Dx and (Bx,s or Cx,f))\n\\forall x ((Dx -> (~Bx,s and ~Cx,f))\n\\forall x ((Dx -> ~(Bx,s or Cx,f))\n
Scope ambiguity
e.g. Some boy kissed every girl.
\\exist x \\forall y (Bx and (Gy -> Kx,y)) = \\exist x(Bx and \\forall y (Gy -> Kx,y))\n\\forall y \\exist x (Gy -> (Bx and Kx,y)) = \\forall y (Gy -> \\exist x (Bx and Kx,y))\n
Every boy kissed some girl.
\\forall x (Bx -> \\exist (Gy and Kxy)) <=> \\forall x \\exist y (Gy and Kxy)\n
Every students did not laugh.
\\forall x (Sx -> ~Lx) <=> ! \\exist x (Sx and Lx)\n~\\forall x (Sx -> Lx) <=> \\exist (Sx and ~Lx)\n
Not every student laughs.
~\\forall x (Sx -> Lx) <=> \\exist (Sx and ~Lx)\n
graph TD\n laughed --> student\n student --> /every\n /every --> not\n
each studnet did not laugh.
\\forall x (Sx -> ~Lx) \n~\\forall x (Sx -> Lx)\n
"},{"location":"Ling/Semantics/formal_semantics/#polarity-item","title":"Polarity item","text":"any: negative polarity item
John did not pass every exam.
~\\forall x (Ex -> Pj,x) <=> \\exist x (Ex and Pj,x)\n\\forall x (Ex -> ~Pj,x)\n
John did not pass any exam.
\\forall x (Ex -> ~Pj,x)\n
e.g.
Jack saw a rat.
\\exist x (Rx and Sj,x) \n
Jack is a rat.
the quantifier is in the predicate but not the argument. here rat is a constant.
Rj\n
Jack knows no genius.
use not exist to render \u201cno\u201d
~\\exist x (Gx and Kj,x) <=> \\forall x (Gx -> ~Kj,x)\n
Jack is no genius. <=> Jack is not a genius.
~Gj\n
These problems are difficult.
Dp\n
These problems are difficult ones.
Dp\n
All the problems are difficult.
\\forall x (Px -> Dx)\n
These problems are all the problems.
Ap\n
These problems are not all the problems.
~Ap\n
Jack is our plumber.
Pj\n
Our plumer is Jack. (has presupposition)
Pj\n
Everything counts.
whether thing includes animate and inanimate.
\\forall x (Cx)\n\\forall x (Tx -> Cx)\n
Everybody counts.
*\\forall x (Cx)\n\\forall x (Px -> Cx)\n
predicates
some prepositions.
The present under the tree is big. (prepositions that gives location)
argument nouns.
common nouns
content verbs are the core of syntactic predicates
adjectives are most always the core of syntactic predicates.
e.g. Mike\u2019s wife thinks Mikes if lazy.
predicates inside individual constants are presuppositional
A thin man was present.
predicates inside \u2026 .are propositional
e.g. Every barking is harmless
has true or false impact on the truth
\\forall x ((Dx and Bx) -> Hx)\n
this proposition has to show up in the predicate
The barking dog is harmless.
Hd\n
the presupposition does not show in the predicate
John avoids every dog he sees.
\\forall x ((Dx and Sj,x) -> Aj,x)\n
John said every dog barks.
intensional
Sj\nS(j,\\forall x (Dx -> Bx)) \nSj,I ; I for intensional argument predicate\n
"},{"location":"Ling/Semantics/formal_semantics/#adjunct-predicates","title":"Adjunct predicates","text":"Jane probably teased Sam last night
John arrived drunk.
Jim burped twice.
twice: propositional or presuppositional
Susan did not cheat yesterday.
Mary stayed because John stayed.
Mary did not stay because John stayed
Every boy was hungry
\\forall x: Bx(Hx)\n
Some boy was hungry.
\\exist x: Bx(Hx)\n
Every cat barfed.
\\forall x: Cx(Bx)\n
Bill fed every cat.
\\forall x (Cx, Fb,x)\n\\forall x: Cx(Fb,x)\n
Some dog barked at Fred.
\\exist x (Dx, Bx,f)\n\\exist x: Dx(Bx,f)\n
Fred and Susan avoid some dog.
\\exist x(Dx and (Af,x and As,x))\n\\exist x: Dx (Af,x and Af,x)\n
No dog barks.
~\\exist x (Dx and Bx) <=> ~\\exist x: Dx (Bx)\n
"},{"location":"Ling/Semantics/formal_semantics/#formal-predicate-semantics","title":"Formal Predicate Semantics","text":"graph TD\n Semantic_Rules --> Model\n Semantic_Rules --> Valuation_Function\n Model --> Universe_of_Discourse\n Model --> Interpretation_Function\n Universe_of_Discourse --> entities\n
interpretation function I
I(name) \u2192 meaning\n
assignment function g[x/e]
g(type of object) -> meaning\n
valuation function V
V(p) = 1/0\nV(Bs) = 1/0\n
[[\\alpha]]^M the denotation of \\alpha wrt M (same as interpretation function I)
[[name]]^M -> meaning\n
\u751f\u6210\u53e5\u6cd5\u548c\u6210\u5206\u53e5\u6cd5\u4e4b\u95f4\u7684\u533a\u522b
[The big book of poems with the blue cover] is on the table.\n
\u6210\u5206\u53e5\u6cd5\u505a\u51fa\u6765\uff0csubject\u662f\u4e00\u4e2a\u9ad8\u5ea6\u4e3a1\u7684\u6811
\u53e5\u5b50\u4e4b\u95f4\u7684\u6210\u5206\u901a\u8fc7\u4e24\u4e24\u7ec4\u5408\u8fd8\u80fd\u505a\u51fa\u65b0\u7684\u9ad8\u5ea6
one-replacement
\u7528one-replacement\u63a2\u6d4b\u9650\u5b9a\u8bcd\u4e4b\u95f4\u7684\u8ddd\u79bb\u5173\u7cfb\uff08\u52a8\u8bcd\u7528did so/did too\uff09
Mika loved the policeman intensively.\nSusan did so half-heartedly.\n*Susan did so the baker.\n
graph TD\n NP --> D\n D --> the\n NP --> N1\n N1 --> AdjP\n AdjP --> big\n N1 --> N2\n N2 --> N3\n N2 --> PP1\n N3 --> N\n N --> book\n N3 --> PP2\n PP2 --> of_poems\n PP1 --> with_the_blue_cover\n
\u52a0\u5165\u4e86bar level\uff0cbook\u4e0eof poems\u6784\u6210\u4e00\u4e2a\u4e2d\u95f4\u6295\u5c04X-bar\uff0c\u6784\u6210\u4e00\u4e2aconstituent\u3002\u4f7f\u5f97\u6bcf\u4e2a\u53e5\u5b50\u90fd\u80fd\u88ab\u753b\u6210\u4e00\u4e2a\u4e8c\u53c9\u6811\u5f62\u5f0f
\u751f\u6210\u53e5\u6cd5\u5b66\u6d3e\uff1a\u4e0a\u4e16\u7eaa\u4e94\u5341\u5e74\u4ee3\u3002classical theory and standard theory\u30021988\u5e74\u63d0\u51fa\u4e86government and binding theory\u3002lexicon, D-S, S-S, PF, LF
"},{"location":"Ling/Syntax/conv_gen/#n-bar","title":"N-bar","text":"\u539f\u672cNP\u6839\u636e\u4e00\u7cfb\u5217\u89c4\u5219\u4e0d\u662f\u4e8c\u53c9\u6811\uff0c\u6bd4\u5982N\u2192
N-bar theory\u8ba4\u4e3a\u53ef\u4ee5\u90fd\u53d8\u6210\u4e8c\u53c9\u6811
\u89c4\u5219\u6bd4\u5982
NP -> Det N'\nN' -> AP N'\nN' -> N PP\n
\u7b2c\u4e00\u6761\u79f0\u4e3a\u4e00\u4e2a\u6700\u5927\u6295\u5c04
"},{"location":"Ling/Syntax/conv_gen/#v-bar","title":"V-bar","text":"VP -> V' // \u9884\u7559\u4e00\u4e2a\u4f4d\u7f6e\u7ed9\u6f5c\u5728\u7684specifier\uff0c\u5373\u4f7f\u6ca1\u6709\nV' -> AdvP V' | V' PP | V' AdvP\nV' -> V(NP)\n
"},{"location":"Ling/Syntax/conv_gen/#abj-bar","title":"Abj-bar","text":"AdjP -> Adj'\nAdj' -> (AdvP) Adj' | Adj' (AdvP)\nAdj' -> Adj(PP)\n
"},{"location":"Ling/Syntax/conv_gen/#p-bar","title":"P-bar","text":"PP -> P'\nP' -> P'(PP) | (AdvP)P'\nP' -> P(NP)\n
\u4e2d\u5fc3\u8bcdX \u2192 \u4e2d\u95f4\u6295\u5c04X\u2019 \u2192 \u6700\u5927\u6295\u5c04XP\u3002\u4e0d\u80fd\u76f4\u63a5\u5230XP\uff0c\u4e00\u5b9a\u8981\u6709\u4e2d\u95f4\u6295\u5c04
"},{"location":"Ling/Syntax/conv_gen/#parameter-of-word-orders","title":"Parameter of Word Orders \u7ba1\u7ea6\u8bba\uff0c \u539f\u5219\u4e0e\u53c2\u6570\u7406\u8bba","text":"\u6839\u636eX-bar\u7406\u8bba\uff0c\u53ef\u4ee5\u5bf9\u4e00\u4e9b\u8bed\u8a00\u7684\u4e0d\u540c\u8bed\u5e8f\uff08\u5982SVO\uff0cSOV\u7b49\uff09\u7ed9\u51fa\u8bed\u6cd5\u53c2\u6570\u5316\u89e3\u91ca
specifier\u548ccomplement\u53ef\u4ee5\u51fa\u73b0\u5728\u5176sister\u7684\u4e24\u4fa7\uff0c\u8fd9\u79cd\u6295\u5c04\u7684\u5de6\u53f3\u533a\u522b\u88ab\u79f0\u4e3aparameter setting
"},{"location":"Ling/Syntax/conv_gen/#_2","title":"\u753b\u6811\u7684","text":"head movement: movement from a head to another head position
\u53e5\u5b50\u53ef\u4ee5\u53d1\u751fmovement\u7684\u6807\u5fd7
"},{"location":"Ling/Syntax/conv_gen/#-reading","title":"- \u4e00\u4e2a\u53e5\u6cd5\u7ed3\u6784\u5177\u6709\u4e24\u79cdreading","text":"shortest movement
shortest: let the path of a movement be the set of nodes that dominate the original position of the moved item, and do not dominate the leading site.
"},{"location":"Ling/Syntax/ud_sud/","title":"\u4f9d\u5b58\u53e5\u6cd5 UD & SUD","text":"In full spelling, Universal Dependency gammar and Surface Syntax Universal Dependency grammar.
"},{"location":"Ling/Syntax/ud_sud/#tools","title":"Tools","text":"AllenNLP Demo CoreNLP Tool
"},{"location":"Ling/Syntax/ud_sud/#concepts","title":"Concepts","text":"Dependency grammar\u00a0(DG) is an approach to the study of the syntax and grammar of natural languages that is quite distinct from\u00a0phrase structure grammar\u00a0(PSG), which is also known as\u00a0constituency grammar. The modern history of DG begins with\u00a0Lucien Tesni\u00e8re's major oeuvre (1959), whereas the modern history of PSG begins arguably with\u00a0Noam Chomsky's first prominent work (1957).
DG views linguistic structures in terms of a\u00a0one-to-one mapping\u00a0of atomic linguistic units to the nodes in structure, whereas PSG assumes a\u00a0one-to-one-or-more mapping. The distinction is clearly visible when one compares the tree structures. The next trees are taken from the\u00a0Wikipedia article on DG:
"},{"location":"Ling/Syntax/ud_sud/#sud","title":"SUD","text":"[Surface Syntactic Universal Dependencies (SUD) | SUD](https://surfacesyntacticud.github.io/ SUD is an annotation scheme for syntactic dependency treebanks, and has a nearly perfect degree of two-way convertibility with the Universal Dependencies scheme (UD). Contrary to UD, it is based on syntactic criteria (favoring functional heads) and the relations are defined on distributional and functional bases.
"},{"location":"Ling/Syntax/ud_sud/#general-principles-of-sud","title":"General principles of SUD","text":"SUD has 4 specific syntactic relations and a few extended relations: - subj - udep - comp - comp:aux - comp:cleft - comp:obj - comp:obl - comp:pred - mod
"},{"location":"Ling/Syntax/uni_gram/","title":"\u666e\u904d\u8bed\u6cd5 Universal Grammar","text":""},{"location":"Ling/Syntax/uni_gram/#introduction","title":"Introduction","text":"Syntax\u7684\u610f\u4e49\u5728\u4e8e\u627e\u5230\u4e00\u79cdgrammar\uff0c\u80fd\u591f\u751f\u6210\u67d0\u79cd\u8bed\u8a00\u4e2d\u7684\u6240\u6709\u53e5\u5b50\u3002
Grammar\u662f\u57fa\u4e8e\u89c4\u5219\u7684\uff0c\u4e0d\u80fd\u7528high order of statistical approximation to English\u6765\u66ff\u4ee3\u3002
"},{"location":"Ling/Syntax/uni_gram/#basic-linguistics","title":"Basic Linguistics","text":"DFA & Regular language
\u8c13\u8bcd\u903b\u8f91\u3002\u4f46\u6211\u4eec\u4e0d\u5173\u5fc3\u5176\u4e2d\u7684\u8bed\u4e49\uff0c\u53ea\u9700\u5173\u5fc3CFG\u7684\u5f62\u5f0f\u3002
"},{"location":"Ling/Syntax/uni_gram/#phrase-structure-limitation","title":"Phrase Structure & Limitation","text":"\u81ea\u7136\u8bed\u8a00\u7684CFG\uff08\u4ee5\u82f1\u8bed\u4e3a\u4f8b\uff09\u6784\u6210\u8bed\u6cd5\u7684\u57fa\u7840\u90e8\u5206\u3002
\u4f46\u8fd9\u6837\u63cf\u8ff0\u81ea\u7136\u8bed\u8a00\u7684\u5de5\u5177\u8fd8\u662f\u4e0d\u80fd\u751f\u6210\u6240\u6709\u5408\u7406\u7684\u53e5\u5b50\uff0c\u6545\u5f15\u5165a more powerful model combining phrase structure and grammatical transformation\uff0c\u5f97\u5230\u8f6c\u6362-\u751f\u6210\u6587\u6cd5\u3002
"},{"location":"Ling/Syntax/uni_gram/#on-the-goals-of-linguistic-theory","title":"On the Goals of Linguistic Theory","text":"\u4ece\u4e00\u822c\u8bed\u6cd5\u4e2d\u5f52\u7eb3\u51faUG\u7406\u8bba\uff0c\u5bf9UG\u7684\u671f\u671b\u7531\u5f3a\u81f3\u5f31\u4e3a\uff1a
\u5e94\u8be5\u7814\u7a76competence\uff0c\u800c\u975eperformance
"},{"location":"Math/","title":"\u7d22\u5f15","text":"\u672c\u4e13\u680f\u5185\u5bb9\u4e3a\u6570\u5b66\u7b14\u8bb0\uff0c\u5305\u62ec\u4ee5\u4e0b\u5206\u652f\uff1a - \u56fe\u8bba - \u79bb\u6563\u6570\u5b66
"},{"location":"Math/normal_forms/","title":"\u5404\u79cdNormal Forms","text":""},{"location":"Math/normal_forms/#conjunctive-normal-form-cnf","title":"Conjunctive Normal Form (CNF)","text":"conjunction of one or more clauses
(A or ~B or ~C) and (~D or E or F)\n
"},{"location":"Math/normal_forms/#disjunctive-normal-form","title":"Disjunctive Normal Form","text":"\uff08A and ~B and ~C\uff09or (~D and E and F)\n
"},{"location":"Math/normal_forms/#algebraic-normal-form","title":"Algebraic Normal Form","text":"one more terms are combined into terms by AND, and one more terms are combined by XOR
a XOR b XOR (a AND b) XOR (a AND b AND c)\n
"},{"location":"Math/normal_forms/#negation-normal-form-nnf","title":"Negation Normal Form (NNF)","text":"if the negation operator is only applied to variables and the only other allowed Boolean operators are conjunctions and disjunctions
~A and B\n
"},{"location":"Math/normal_forms/#chomsky-normal-form","title":"Chomsky Normal Form","text":"formal language theory \u5047\u7684
A \u2192 BC\nA \u2192 a\nS \u2192 \u03b5\n
Category:Normal forms (logic)
"},{"location":"Math/questions/","title":"\u96f6\u6563\u7684\u9898","text":"RHS\u6210\u7acb\u7684\u6761\u4ef6\u662f \u5fc5\u987b\u6240\u6709x\u90fd\u4f7fP(x)\u4e0d\u6210\u7acb\uff0c\u624d\u80fd\u4e0d\u7ba1Q(y)\u662f\u5426\u6210\u7acb \u6216\u6240\u6709P(x)\u90fd\u6210\u7acb\uff0c\u4e14Q(y)\u6210\u7acb
\u6240\u4ee5\u5f53\\(\\exists x\\)\u4f7fP(x)\u4e3a\u5047\uff0c\u4f46\u662f\u5176\u5b83x\u4f7fp(x)\u4e3a\u771f\uff0c\u4e14\\(\\forall y\\)\u4f7fQ(y)\u4e3a\u5047\u65f6\uff0cLHS\u662f\u771f\u7684\uff0c\u4f46\u662fRHS\u662f\u5047\u7684\uff0c\u6240\u4ee5LHS\\(\\neq\\)RHS.
\u6309\u7167\u8fd9\u4e2a\u53ef\u4ee5\u4e3e\u4e00\u4e2a\u4f8b\u5b50 U = \u81ea\u7136\u6570 P(x) = x \u662f\u5947\u6570 Q(y) = y \u662f\u8d1f\u6570
"},{"location":"Math/Graph/laplace_matrix/","title":"Laplacian Matrix","text":""},{"location":"Math/Graph/laplace_matrix/#basic-properties","title":"Basic Properties","text":"or L = D(degree matrix) - A(adjacency matrix)
"},{"location":"Math/Graph/laplace_matrix/#normalization","title":"Normalization","text":""},{"location":"Math/Graph/laplace_matrix/#eigendecomposition","title":"Eigendecomposition","text":""},{"location":"Math/Graph/laplace_matrix/#gcnlaplace","title":"\u4e3a\u4ec0\u4e48GCN\u8981\u7528\u5230laplace\u77e9\u9635","text":"Laplacian matrix
"},{"location":"Other/","title":"\u7d22\u5f15","text":"TODO\uff08\u8fd8\u6ca1\u5199\uff09
"},{"location":"Other/apa/","title":"APA Format","text":"\u6211\u559c\u6b22\u7528\u5f15\u6587\u81ea\u52a8\u751f\u6210\u5668\uff0c\u63a8\u8350\u51e0\u4e2a
APA\u683c\u5f0f\u6307\u7684\u662f\u7f8e\u56fd\u5fc3\u7406\u5b66\u4f1a\uff08American Psychological Association\uff0c\u7b80\u79f0APA\uff09\u51fa\u7248\u7684\u300a\u7f8e\u56fd\u5fc3\u7406\u534f\u4f1a\u51fa\u7248\u624b\u518c\u300b\uff08Publication Manual of the American Psychological Association\uff09\u3002\u5b83\u8d77\u6e90\u4e8e1929\u5e74\uff0c\u5230\u76ee\u524d\u4e3a\u6b62\u5df2\u7ecf\u66f4\u65b0\u81f3\u7b2c\u4e03\u7248\uff0c\u603b\u9875\u6570\u4e5f\u5df2\u7ecf\u8d85\u8fc7400\u9875\uff0c\u91cc\u9762\u8be6\u7ec6\u89c4\u8303\u4e86\u6587\u7ae0\u7684\u9875\u9762\u683c\u5f0f\uff08\u884c\u95f4\u8ddd\u3001\u5b57\u4f53\u3001\u5b57\u53f7\u3001\u9875\u8fb9\u8ddd\u7b49\u7b49\uff09\u3001\u56fe\u8868\u8868\u683c\\\u53c2\u8003\u6587\u732e\u7b49\u7b49\uff0c\u6781\u4e3a\u5168\u9762\u3002APA\u4e3b\u8981\u7528\u4e8e\u5fc3\u7406\u3001\u6559\u80b2\u53ca\u793e\u4f1a\u79d1\u5b66\u7b49\u5b66\u79d1\u3002\u5176\u89c4\u8303\u683c\u5f0f\u4e3b\u8981\u5305\u62ec\u6587\u5185\u6587\u732e\u5f15\u7528\uff08Reference Citations in Text\uff09\u548c\u6587\u672b\u53c2\u8003\u6587\u732e\u5217\u8868\uff08Reference List\uff09\u4e24\u5927\u90e8\u5206\u3002
APA\u683c\u5f0f\u5f3a\u8c03\u51fa\u7248\u7269\u7684\u5e74\u4ee3\uff08Time of the Publication Year\uff09\u800c\u4e0d\u5927\u6ce8\u91cd\u539f\u6587\u4f5c\u8005\u7684\u59d3\u540d\u3002\u5f15\u6587\u65f6\u5e38\u5c06\u51fa\u7248\u5e74\u4ee3\u7f6e\u4e8e\u4f5c\u8005\u7f29\u5199\u7684\u540d\uff08the Initial of Author\u2019s First Name\uff09\u4e4b\u524d\u3002
\u4e00\u3001\u6587\u5185\u6587\u732e\u5f15\u7528\uff08ReferenceCitations in Text\uff09
1.\u5355\u4e00\u4f5c\u8005
\u683c\u5f0f\u5e94\u4e3a\u201c\uff08\u4f5c\u8005\u59d3\u6c0f\uff08\u975e\u9996\u5b57\u6bcd\uff09\uff0c\u53d1\u8868\u5e74\u4efd\uff09\u201d\u3002\u82e5\u4f5c\u8005\u59d3\u540d\u5728\u6587\u7ae0\u4e2d\u5df2\u88ab\u63d0\u53ca\uff0c\u53ea\u9700\u6807\u51fa\u5e74\u4efd\u5c31\u597d\uff08\u82e5\u9700\u8981\u53ef\u52a0\u4e0a\u9875\u6570\uff09\uff0c\u4ecd\u9700\u4f7f\u7528\u62ec\u53f7\u3002\u591a\u4f4d\u4f5c\u8005\u4ee5\u4e0a\u540c\u7406\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, 2005). Pauling (2005) discovered a possible genetic cause of alcoholism.
2.\u4e24\u4f4d\u4f5c\u8005
\u4f5c\u8005\u59d3\u6c0f\u5fc5\u987b\u4ee5\u4ed6\u4eec\u7684\u540d\u5b57\u5728\u5176\u53d1\u8868\u6587\u7ae0\u5185\u7684\u987a\u5e8f\u6765\u6392\u5e8f\u3002\u82e5\u4e24\u4e2a\u4f5c\u8005\u90fd\u5728\u62ec\u53f7\u5185\u5f15\u7528\uff0c\u540d\u5b57\u4e2d\u95f4\u9700\u52a0\u4e0a\u201c&\u201d\u7b26\u53f7\uff1b\u82e5\u4e0d\u5728\u62ec\u53f7\u5185\u5219\u4f7f\u7528\u201cand\u201d\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling & Liu, 2005). Pauling and Liu (2005) discovered a possible genetic cause of alcoholism.
3.\u4e09\u81f3\u4e94\u4f4d\u4f5c\u8005
\u7b2c\u4e00\u6b21\u5f15\u7528\u65f6\u9700\u5217\u4e3e\u5168\u90e8\u7684\u4f5c\u8005\uff0c\u5f80\u540e\u82e5\u5f15\u7528\u76f8\u540c\u7684\u6587\u732e\uff0c\u53ea\u9700\u4e3e\u51fa\u6700\u4e3b\u8981\u7684\u4f5c\u8005\uff0c\u518d\u52a0\u4e0a\u201cet al.\u201d\u3002\u4f46\u662f\uff0c\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0c\u5168\u90e8\u4f5c\u8005\u7684\u59d3\u540d\u7686\u987b\u5217\u4e3e\u51fa\u6765\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, Liu, & Guo, 2005). Pauling, Liu, and Guo (2005) conducted a study that discovered a possible genetic cause of alcoholism. Pauling et al. (2005) discovered a possible genetic cause of alcoholism. A recent study found a possible genetic cause of alcoholism (Pauling et al., 2005).
4.\u516d\u4f4d\u4f5c\u8005\u4ee5\u4e0a
\u4e3e\u51fa\u7b2c\u4e00\u4f4d\u4f5c\u8005\u5373\u53ef\uff0c\u683c\u5f0f\u5e94\u4e3a\u201c\uff08\u4f5c\u8005\u00a0et al.\uff0c\u5e74\u4efd\uff09\u201d\u3002\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0c\u5168\u90e8\u4f5c\u8005\u7684\u59d3\u540d\u7686\u987b\u5217\u4e3e\u51fa\u6765\u3002\u4f8b\u5982\uff1a
Pauling et al. (2005) discovered a possible genetic cause of alcoholism.
5.\u591a\u7bc7\u6587\u732e\uff0c\u540c\u4e00\u4f5c\u8005
\u82e5\u4e00\u4f5c\u8005\u6709\u591a\u7bc7\u4f60\u60f3\u5f15\u7528\u7684\u6587\u732e\uff0c\u53ea\u9700\u7528\u9017\u53f7\u6765\u533a\u9694\u4f5c\u54c1\u7684\u53d1\u8868\u5e74\u4efd\uff08\u6700\u65e9\u5230\u6700\u665a\u4f9d\u5e8f\u6392\u5217\uff09\u3002\u82e5\u591a\u7bc7\u6587\u732e\u5728\u540c\u4e00\u5e74\u5185\u53d1\u8868\uff0c\u8bf7\u5728\u5e74\u4efd\u540e\u9762\u52a0\u4e0aa\u3001b\u3001c\u2026\u2026\u7b49\u6807\u6ce8\u3002\uff08\u6309\uff1aabc\u7684\u4f7f\u7528\u9700\u4e0e\u53c2\u8003\u6587\u732e\u90e8\u5206\u6709\u6240\u5bf9\u5e94\uff0c\u800c\u8fd9\u4e9b\u6587\u732e\u7684\u7f16\u6392\u4ee5\u6807\u9898\u540d\u79f0\u7684\u5b57\u6bcd\u6765\u51b3\u5b9a\u3002\uff09\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, 2004, 2005a, 2005b). Pauling (2004, 2005a, 2005b) conducted a study that discovered a possible genetic cause of alcoholism
6.\u591a\u7bc7\u6587\u732e\uff0c\u591a\u4f4d\u4f5c\u8005
\u6839\u636e\u4e0a\u4e00\u4e2a\u7684\u89c4\u5219\uff0c\u5e76\u4e14\u4f7f\u7528\u5206\u53f7\u9694\u5f00\u3002\u6392\u5e8f\u5148\u4f9d\u7167\u4f5c\u8005\u59d3\u6c0f\u7684\u5b57\u6bcd\uff0c\u63a5\u7740\u662f\u53d1\u8868\u5e74\u4efd\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Alford, 1995; Pauling, 2004, 2005; Sirkis, 2003)
7.\u76f4\u63a5\u5f15\u8ff0
\u683c\u5f0f\u4e0e\u524d\u8ff0\u65e0\u4e0d\u540c\uff0c\u4e00\u6837\u4e3a\u201c\uff08\u4f5c\u8005\uff0c\u5e74\u4efd\uff0c\u9875\u6570\uff09\u201d\u3002\u4f8b\u5982\uff1a
When asked why his behavior had changed so dramatically, Max simply said \u201cI think it\u2019s the reinforcement\u201d (Pauling, 2004, p. 69).
\u4e8c\u3001\u6587\u672b\u53c2\u8003\u6587\u732e\u5217\u8868\uff08Reference List\uff09
\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0cAPA\u683c\u5f0f\u89c4\u5b9a\u90e8\u5206\u7684\u4eba\u540d\u5fc5\u987b\u4ee5\u59d3\uff08Family name\uff09\u7684\u5b57\u6bcd\u987a\u5e8f\u6765\u6392\u5217\uff0c\u5305\u62ec\u540d\uff08first name\uff09\u7684\u524d\u7f00\u3002
1.\u5355\u4e00\u4f5c\u8005\u8457\u4f5c\u7684\u4e66\u7c4d\u3002\u4f8b\u5982\uff1a
Sheril, R. D. (1956).\u00a0The terrifying future: Contemplating color television. San Diego: Halstead.
2.\u4e24\u4f4d\u4f5c\u8005\u4ee5\u4e0a\u5408\u8457\u7684\u4e66\u7c4d\u3002\u4f8b\u5982\uff1a
Smith, J., & Peter, Q. (1992).\u00a0Hairball: An intensive peek behind the surface of an enigma. Hamilton, ON: McMaster University Press.
3.\u6587\u96c6\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Mcdonalds, A. (1993). Practical methods for the apprehension and sustained containment of supernatural entities. In G. L. Yeager (Ed.),\u00a0Paranormal and occult studies: Case studies in application\u00a0(pp. 42\u201364). London: OtherWorld Books.
4.\u671f\u520a\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Crackton, P. (1987). The Loonie: God\u2019s long-awaited gift to colourful pocket change?\u00a0Canadian Change, 64(7), 34\u201337.
5.\u6708\u520a\u6742\u5fd7\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Henry, W. A., III. (1990, April 9). Making the grade in today\u2019s schools.\u00a0Time, 135, 28-31.
6.\u62a5\u7eb8\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Wrong, M. (2005, August 17). Misquotes are \u201cProblematastic\u201d says Mayor.\u00a0Toronto Sol.,\u00a04.
7.\u653f\u5e9c\u5b98\u65b9\u6587\u732e
Revenue Canada. (2001).\u00a0Advanced gouging: Manual for employees\u00a0(MP 65\u2013347/1124). Ottawa: Minister of Immigration and Revenue.
8.\u9488\u5bf9\u7535\u5b50\u6587\u732e\u3001\u7f51\u7ad9\u548c\u7ebf\u4e0a\u6587\u7ae0\uff0cAPA\u683c\u5f0f\u7684\u7f51\u7ad9\u4e0a\u6709\u8ba2\u5b9a\u4e00\u4e9b\u57fa\u672c\u7684\u89c4\u5219\uff0c\u7b2c\u4e00\u5c31\u662f\u63d0\u4f9b\u8bfb\u8005\u8be6\u7ec6\u7684\u6587\u732e\u5185\u5bb9\u6765\u6e90\uff0c\u7b2c\u4e8c\u4e3a\u63d0\u4f9b\u5176\u6709\u6548\u7684\u53c2\u8003\u6765\u6e90\u3002
\u2474\u00a0\u7f51\u7edc\u6587\u7ae0\u7684\u6253\u5370\u7248\u672c
Marlowe, P., Spade, S., & Chan, C. (2001). Detective work and the benefits of colour versus black and white [Electronic version].Journal of Pointless Research, 11,123\u2013124.
\u2475\u00a0\u7535\u5b50\u671f\u520a\u7684\u6587\u7ae0\uff08\u53ea\u6709\u7f51\u7edc\u7248\u7684\u671f\u520a\uff09
Blofeld, E. S. (1994, March 1). Expressing oneself through Persian cats and modern architecture.Felines & Felons, 4,Article 0046g. Retrieved October 3, 1999, from\u00a0\u7f51\u9875\u5730\u5740.
\u2476\u00a0\u7535\u5b50\u77ed\u4fe1\uff08newsletter\uff09\u7684\u6587\u7ae0
Paradise, S., Moriarty, D., Marx, C., Lee, O. B., Hassel, E., et al. (1957, July). Portrayals of fictional characters in reality-based popular writing: Project update.Off the beaten path, 7(3). Retrieved October 3, 1999, from\u00a0\u7f51\u9875\u5730\u5740.
\u2477\u00a0\u5355\u7bc7\u7ebf\u4e0a\u6587\u732e\uff08\u65e0\u4f5c\u8005\u53ca\u8457\u4f5c\u65e5\u671f\uff09
What I did today.(n.d.). Retrieved August 21, 2002, from\u00a0\u7f51\u9875\u5730\u5740.
\u2478\u00a0\u4ece\u5927\u5b66\u8bfe\u7a0b\u6216\u7cfb\u4e0a\u7f51\u7ad9\u53d6\u5f97\u7684\u6587\u732e
Rogers, B. (2078).Faster-than-light travel: What we\u2019ve learned in the first twenty years.Retrieved August 24, 2079, from Mars University, Institute for Martian Studies Web site:\u00a0\u7f51\u9875\u5730\u5740.
\u2479\u00a0\u4ece\u6570\u636e\u5e93\u641c\u5bfb\u7684\u671f\u520a\u6587\u7ae0\u7684\u7535\u5b50\u590d\u5236\u7248\u672c\uff083\u81f35\u4f4d\u4f5c\u8005\uff09
Costanza, G., Seinfeld, J., Benes, E., Kramer, C., & Peterman, J. (1993).\u00a0Minuti\u00e6 and insignificant observations from the nineteen-nineties.Journal about Nothing, 52,475\u2013649. Retrieved October 31, 1999,\u00a0from NoTHINGJournals database.
\u247a\u00a0\u7535\u5b50\u90ae\u4ef6\u6216\u5176\u4ed6\u4e2a\u4eba\u901a\u8baf\uff08\u4e0d\u51fa\u73b0\u5728\u53c2\u8003\u6587\u732e\u5217\u8868\u4e2d\uff0c\u4ec5\u5728\u6587\u4e2d\u6807\u51fa\uff09\u3002\u4f8b\u5982\uff1a
(A. Monterey, personal communication, September 28, 2001).
9.\u50a8\u5b58\u4e8e\u5149\u789f\u7684\u4e66\u7c4d
Nix, G. (2002).\u00a0Lirael, Daughter of the Clayr\u00a0[CD].\u00a0New York: Random House/Listening Library.
10.\u50a8\u5b58\u4e8e\u5f55\u97f3\u5e26\u7684\u4e66\u7c4d
Nix, G. (2002).\u00a0Lirael, Daughter of the Clayr\u00a0[Cassette Recording No. 1999-1999-1999]\u3002New York: Random House/Listening Library.
APA\u683c\u5f0f\u8303\u6587\u53ef\u6d4f\u89c8\u7f51\u9875\uff1a
MLA Sample Essay
\u5176\u8be6\u7ec6\u7684\u4ecb\u7ecd\u53ef\u53c2\u770b\u7f8e\u56fd\u4f5b\u8499\u7279\u5927\u5b66\u56fe\u4e66\u9986\u5927\u536b\u2022W\u2022\u8c6a\u7eaa\u5ff5\u56fe\u4e66\u9986\uff08David W. Howe Memorial Library of THE UNIVERSITY OF VERMONT Libraries\uff09\u7f51\u7ad9\u4e0a\u7684\u201cAPA (American Psychological Association) Style\u201d\u7f51\u9875\uff08\u7f51\u5740\uff1a
APA (American Psychological Association) Style | Howe Library
"},{"location":"Other/nlp_resources/","title":"DL & NLP Resources","text":""},{"location":"Other/nlp_resources/#machine-learning-theory","title":"Machine Learning Theory","text":"Google\u7684\u4e00\u4e2a\u6559\u7a0b\uff0c\u91cc\u9762\u7684playground\u505a\u5f97\u6bd4\u8f83\u76f4\u89c2\uff0c\u65e0\u9700\u4ee3\u7801
Machine Learning \u00a0|\u00a0 Google for Developers
"},{"location":"Other/nlp_resources/#machine-learning-technology","title":"Machine Learning Technology","text":"TODO
"},{"location":"Other/nlp_resources/#deep-learning-theory","title":"Deep Learning Theory","text":"TODO
"},{"location":"Other/nlp_resources/#deep-learning-technology","title":"Deep Learning Technology","text":"Pytorch\u6559\u7a0b\uff0c\u53ef\u4ee5\u770b\u7740\u4ee3\u7801\u624b\u6284\u4e00\u4e0b
Welcome to PyTorch Tutorials \u2014 PyTorch Tutorials 2.0.1+cu117 documentation
numpy: numpy 100 exercise
rougier/numpy-100: 100 numpy exercises (with solutions) (github.com)
Pytorch
PyTorch\u6df1\u5ea6\u5b66\u4e60\u5feb\u901f\u5165\u95e8\u6559\u7a0b\uff08\u7edd\u5bf9\u901a\u4fd7\u6613\u61c2\uff01\uff09\u3010\u5c0f\u571f\u5806\u3011_\u54d4\u54e9\u54d4\u54e9_bilibili
Attention-based Models and Transformer
Let's build GPT: from scratch, in code, spelled out. - YouTube
"},{"location":"Other/nlp_resources/#natural-language-processing-theory","title":"Natural Language Processing Theory","text":"Stanford CS224N: NLP with Deep Learning | Winter 2021 | Lecture 1 - Intro & Word Vectors - YouTube
"},{"location":"Other/nlp_resources/#natural-language-processing-technology","title":"Natural language processing technology","text":"Stanford CS 224N | Natural Language Processing with Deep Learning
"},{"location":"Other/nlp_resources/#reinforcement-learning","title":"Reinforcement Learning","text":"\u8611\u83c7\u4e66EasyRL (datawhalechina.github.io)
Codes:
boyu-ai/Hands-on-RL: https://hrl.boyuai.com/ (github.com) datawhalechina/easy-rl: \u5f3a\u5316\u5b66\u4e60\u4e2d\u6587\u6559\u7a0b\uff08\u8611\u83c7\u4e66\uff09\uff0c\u5728\u7ebf\u9605\u8bfb\u5730\u5740\uff1ahttps://datawhalechina.github.io/easy-rl/
"},{"location":"Other/nlp_resources/#computer-vision","title":"Computer Vision","text":"Computer Vision | Universit\u00e4t T\u00fcbingen (uni-tuebingen.de)
"},{"location":"Other/tools/","title":"\u6211\u7684\u5de5\u5177\u7bb1\uff01","text":"\u8bb0\u5f55\u4e00\u70b9\u597d\u7528\u7684\u5de5\u5177\u54c8
"},{"location":"Other/tools/#workflow","title":"\u6211\u7684workflow","text":""},{"location":"Other/tools/#notionobsidian","title":"\u9009\u62e9Notion\u548cObsidian","text":"\u5148\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7ed3\u8bba
\u4f18\u70b9/\u5de5\u5177 Notion Obsidian \u8bed\u6cd5 \u81ea\u5df1\u7684\u4e00\u5957\u8bed\u6cd5\uff0c\u90e8\u5206\u662fmarkdown \u7eafmarkdown \u4e66\u5199\u901f\u5ea6 \u6162 \u5feb \u6587\u6863\u6574\u9f50\u7a0b\u5ea6 \u9ad8 \u4f4e \u90e8\u7f72\u5230mkdocs\u96be\u6613 \u6613\uff0c\u53ef\u76f4\u63a5\u7528 \u96be\uff0c\u9700\u8c03\u6574\u5f88\u591a\u683c\u5f0f \u5bfc\u51fa\u4e2d\u6587\u652f\u6301\u7a0b\u5ea6 \u53ea\u6709\u4e09\u79cd\u5b57\u4f53\uff0c\u90e8\u5206\u4e2d\u6587\u7f3a\u5b57 \u5b57\u4f53\u591a\uff0c\u652f\u6301\u6bd4\u8f83\u597d\u76ee\u524d\u6211\u9009\u62e9\u7684workflow
graph TD\n \u542c\u5199 --> Notion \n Notion -- \u6709\u65f6\u95f4 --> Obsidian\n \u6709\u65f6\u95f4\u6162\u6162\u5199 --> Obsidian\n Obsidian -- \u4f7f\u7528\u540c\u4e00\u6587\u4ef6\u5939 --> mkdocs\n
Obsidian to mkdocs 1. \u56fe\u7247\u8def\u5f84\u95ee\u9898\uff1a \u9700\u8981\u5728\u8bbe\u7f6e\u4e2d\u5173\u95ed\u4f7f\u7528wiki\u8def\u5f84\uff0c\u4fdd\u8bc1\u6240\u6709\u56fe\u7247\u90fd\u7528md\u8bed\u6cd5![]()
\u4e14\u9700\u8981\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\uff0c\u5373\u524d\u9762\u52a0./
\u7684\u90a3\u79cd
TODO
"},{"location":"Other/tools/#_2","title":"\u6587\u732e\u7ba1\u7406\u5de5\u5177","text":"TODO
\u5176\u5b9e\u4ed3\u5e93\u91cc\u672c\u6587\u4ef6\u5939\u4e0b\u7684asset\u91cc\u73b0\u5728\u6709\u4e2a\u600e\u4e48\u914d\u7f6ezotero\u7684ppt\uff0c\u592a\u61d2\u6ca1\u65f6\u95f4\u6574\u8fc7\u6765\uff0c\u53ef\u4ee5\u5148\u53bb\u4ed3\u5e93\u91cc\u627e\u627eorz
"},{"location":"Other/tools/#_3","title":"\u96f6\u6563\u5de5\u5177","text":""},{"location":"Other/tools/#_4","title":"\u4e8c\u7ef4\u7801\u751f\u6210\u5668","text":"\u751f\u6210\u957f\u5f97\u4e0d\u50cf\u4e8c\u7ef4\u7801\u7684\u4e8c\u7ef4\u7801 \u76f4\u63a5\u626b\u4e0b\u9762\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u8fdb\u5165\u7f51\u7ad9
"},{"location":"Other/zotero/","title":"Zotero","text":""}]} \ No newline at end of file +{"config":{"lang":["ja"],"separator":"[\\s\\-\uff0c\u3002]+","pipeline":["stemmer"]},"docs":[{"location":"","title":"Home","text":"Hi there \ud83d\udc4b
"},{"location":"#_1","title":"\u6253\u62db\u547c\u7528\u7684","text":"\u6211\u7684BLOG\uff0c\u4e3b\u8981\u8bed\u8a00\u662f\u4e2d\u6587\uff0c\u4e3b\u8981\u5185\u5bb9\u6709\u7b14\u8bb0 + \u4e00\u4e9b\u778e\u8bdd
\u6211\u7684\u7b14\u8bb0\u4e0d\u591a\uff01\u4ee5\u540e\u4e5f\u4e0d\u4f1a\u591a\u7684\ud83d\ude24 \u6b22\u8fce\u6765\u770b\u6211\u7684\u7b14\u8bb0\uff01
\u5982\u679c\u60f3\u67e5\u627eZJU\u8bfe\u7a0b\u8d44\u6599\uff0c\u53ef\u4ee5\u914d\u5408\u4ed3\u5e93ZJU_COURSE_MATERIALS\u98df\u7528
\u6682\u65f6\u8fd9\u6837\u5206\u5de5
\u5927\u90e8\u5206\u5185\u5bb9\u8fd8\u5728\u4e00\u70b9\u4e00\u70b9\u65bd\u5de5\u4e2d\uff0c\u8bf7\u7a0d\u7b49\uff01
"},{"location":"#_2","title":"\u63a8\u8350\u9605\u8bfb","text":""},{"location":"#_3","title":"\u7533\u8bf7\u5fc3\u5f97","text":"\u4ece\u82f1\u4e13\u8f6cCS\u548cNLP\u7684\u5efa\u8bae\u5e16\uff01
"},{"location":"#computer-science-notes","title":"Computer Science Notes","text":"C\u5927\u7a0blibgraphics\u8e29\u5751\u6587\u6863 \uff08\u4f46\u5176\u5b9e\u9047\u5230\u7684\u5751\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u8fd9\u91cc\u5217\u51fa\u6765\u7684 \u6b22\u8fceissue\u6216\u90ae\u4ef6\u50ac\u66f4\uff01\uff09
C++\u542c\u8bfe\u7b14\u8bb0
OS\u64cd\u4f5c\u7cfb\u7edf\u7b14\u8bb0
"},{"location":"#deep-learning-notes","title":"Deep Learning Notes","text":"\u62b1\u6b49\uff0c\u8fd9\u680f\u5168\u662fTODO\uff0c\uff0c
"},{"location":"#linguistics-notes","title":"Linguistics Notes","text":"ZJU Semantics Notes \uff08\u867d\u7136\u6392\u7248\u4ecd\u4e0d\u662f\u5f88\u597d\u770b\u4f46\u53ef\u80fd\u662f\u5168\u7f51\u9996\u4e2a\ud83d\ude2d\uff09
"},{"location":"#_4","title":"\u5176\u5b83\u8bfe\u7a0b","text":"ZJU\u6253\u5f00\u827a\u672f\u4e4b\u95e8-\u94a2\u7434\u671f\u672b\u590d\u4e60\u7b14\u8bb0
"},{"location":"#_5","title":"\u5de5\u5177\u63a8\u8350","text":"\u5173\u4e8e\u6211\u600e\u6837\u5728\u7b14\u8bb0\u5de5\u5177Notion\u548cObsidian\u4e4b\u95f4\u505a\u9009\u62e9
"},{"location":"#_6","title":"\u8054\u7cfb\u4f5c\u8005","text":"\ud83d\udceb RuoxiNing@outlook.com \ud83e\uddd1\u200d\ud83d\udcbb https://ruoxining.github.io
"},{"location":"App/","title":"\u7d22\u5f15","text":"\u672c\u7ae0\u8282\u5305\u542b\u5347\u5b66\u7ecf\u9a8c\u548c\u5fc3\u5f97\uff0c\u5df2\u7ecf\u5b8c\u6210 - ZJU\u82f1\u4e13\u8f6cCS/NLP\u7684\u5fc3\u5f97
"},{"location":"App/24fall/","title":"\u3010TODO\u3011\u6211\u768424fall\u7533\u8bf7\u8bb0\u5f55","text":"\u672c\u9875\u9762\u4f1a\u5728\u621112\u6708\u6295\u9012\u5b8c\u7b2c\u4e00\u6279\u7533\u8bf7\u540e\u66f4\u65b0\u4e00\u4e2a\u7533\u8bf7\u8bb0\u5f55\u3002
\u4e3b\u8981\u76ee\u7684\u6709\u5206\u4eab\u6211\u7684\u7ecf\u9a8c\u5fc3\u5f97\u548c\u52aa\u529b\u83b7\u5f97\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u81f4\u529b\u4e8e\u7ef4\u62a4CS\u548clinguistics\u7533\u8bf7\u8d44\u6599\u5f00\u6e90\u7684\u751f\u6001\u3002
\u9884\u8ba1\u66f4\u65b0\u5c0f\u6807\u9898\u6709\uff1a
\u6211\u52a0\u5fc3\u9009\u5355\u4e3b\u8981\u770b\u7684\u98de\u8dc3+opencsapp\uff0c\u7136\u540e\u4ece\u91cc\u9762\u5220\u53bb\u6240\u6709\u7533\u5230\u4e5f\u4e0d\u60f3\u53bb\u7684
"},{"location":"App/24fall/#phd","title":"Ph.D. \u9009\u5bfc","text":""},{"location":"App/24fall/#_2","title":"\u8bed\u8a00\u6210\u7ee9","text":"CMU \u5fc5\u987b\u9001\u5206
Umich Meng ECE\u9700\u8981GRE\uff0c\u5fc5\u987b\u9001\u5206 The University of Michigan school code is 1839.
Uchi MPCS\u9700\u8981GRE\u7684q>85%\uff08\u597d\u50cf\u662f\u8fd9\u4e2a\u6570\uff09\uff0cv\u6ca1\u6709\u8981\u6c42 Please have an official TOEFL or IELTS score sent directly to the University of Chicago. The University's institution code for TOEFL/GRE reporting is 1832
UW CLMS \u5fc5\u987b\u8981\u5b98\u65b9\u9001\u5206 TOEFL/GRE ETS report code: 4854
USC: 4852
UCSD\uff1a4836
"},{"location":"App/24fall/#_3","title":"\u63a8\u8350\u4fe1","text":"\u5927\u7ea612.2\u53f7\u770b\u5230phd\u7533\u8bf7\u7fa4\u91cc\u8bf4\u7684\uff0c\u5176\u5b9e\u4e0d\u8981\u627e3\u4e2a\u63a8\u8350\u4eba\u5c31\u7ed3\u675f\uff0c\u6700\u597d\u63d0\u524d\u627e4\u52305\u4e2a\uff0c\u56e0\u4e3a\u591a\u4ea4\u6ca1\u6709\u5173\u7cfb\uff0c\u5927\u90e8\u5206\u5b66\u6821\u90fd\u6709\u6dfb\u52a0\u591a\u4e2a\u63a8\u8350\u4eba\u7684\u9009\u9879\uff08\u6211\u7684\u9009\u6821\u91cc\u53ea\u6709loo\u548cumich\u4e0a\u9650\u4e09\u4e2a\uff09\uff0c\u4f46\u662f\u7ecf\u5e38\u6709\u63a8\u8350\u4eba\u5fd9\u5fd8\u4e86\u7684\u60c5\u51b5\u3002\u518d\u95ee\u53e6\u4e00\u4e2a\u7fa4\uff0c\u5f97\u5982\u679c\u662fphd\uff0c\u4e0d\u4f1a\u56e0\u4e3a\u6709\u4e00\u4e2a\u63a8\u8350\u4eba\u5fd8\u4e86\u4ea4\u62d2\u4f60\uff0c\u4f46\u662f\u6709\u7684ms\u542c\u8bf4\u4e09\u5c01\u4ea4\u4e0d\u9f50\u5c31\u63d0\u4ea4\u4e0d\u4e86\uff08\u6211\u7684\u6682\u65f6\u6ca1\u9047\u5230\uff09\uff0c\u6216\u8005\u53ef\u80fd\u56e0\u6b64\u65e0\u58f0\u62d2\u4f60\uff0c\u6240\u4ee5\u8fd8\u662f\u63d0\u524d\u627e4\u4e2a\u4ee5\u4e0a\u3002
\u542c\u8bf4USC MSCS\u5b8c\u5168\u4e0d\u770b\u63a8\u8350\u4fe1\uff0c\u56e0\u4e3a\u4e5f\u4e0d\u6562\u591a\u8981\uff0c\u6211\u5c31\u4ea4\u4e86\u4e00\u5c01\uff0c\u8d4c\u3002\u3002\u3002\u3002
Uchi\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1
Rice\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1
CMU\u540c\u4e00\u4e2a\u7533\u8bf7\u7cfb\u7edf\u4e4b\u95f4\u53ef\u4ee5\u5171\u4eab\u63a8\u8350\u4fe1\uff0c\u6bd4\u5982MSCS\u548cPhD\u5171\u4eab\uff0cMLT\u90a3\u4e00\u5927\u4e32\u7684AI\u9879\u76ee\u5171\u4eab\u3002
UCSD\u7684ms\u548cphd\u4e4b\u95f4\u4e0d\u80fd\u5171\u4eab\u63a8\u8350\u4fe1\uff0c\u4f46\u662f\u636e\u8bf4cs ce master\u4e4b\u95f4\u662f\u4e92\u901a\u7684\uff0c\u8ddfgit\u4e0d\u4e92\u901a
Umich\u76ee\u524d\u53ea\u77e5\u9053\u81f3\u5c11ms\u548cmeng\u4e4b\u95f4\u4e0d\u80fd\u5171\u4eab\u63a8\u8350\u4fe1\u3002\u586b\u9519\u4e86\u53ef\u4ee5\u66f4\u6539\u63a8\u8350\u4eba\uff0c\u66f4\u6539\u540e\u65b0\u7684\u63a8\u8350\u4eba\u4f1a\u6536\u5230\u90ae\u4ef6\uff0c\u53ea\u662f\u5728\u4f60\u7684\u7533\u8bf7\u91cc\u8fd8\u662f\u663e\u793a\u539f\u6765\u63a8\u8350\u4eba\u3002
Waterloo\u7684\u63a8\u8350\u4fe1\u5728\u7b2c\u4e00\u6b65\u63d0\u4ea4\u540e1-3\u5929\u5185\u53d1\u51fa\uff0c\u7533\u8bf7\u4eba\u4e0d\u53ef\u51b3\u5b9a\u3002\u6211\u7684\u63a8\u8350\u4eba\u6700\u5feb\u6536\u5230\u7684\u662f\u63d0\u4ea4\u540e1\u5929\u5de6\u53f3\u3002\u4e4b\u540e\u5728ddl\u524d14\u5929\u548c7\u5929\u8fd8\u4f1a\u5404\u81ea\u52a8\u53d1\u4e00\u6b21\u50ac\u4fe1
\u7fa4\u91cc\u8bf4\u7684\uff1a\u8865\u5145\u4e00\u4e2a\u54e5\u5927cs ce ee\u4e5f\u662f\u5171\u7528\u3002\u5e94\u8be5\u662fms
"},{"location":"App/24fall/#_4","title":"\u5957\u74f7","text":"\u7f51\u4e0a\u8bf4\u5957\u5230\u74f7\u624d\u80fd\u7533\u3002\u7533\u8bf7\u8fc7\u7a0b\u4e2d\u5f97\u5230\u7684\u6d88\u606f\u662f\u5957\u74f7\u548c\u7533\u8bf7\u5e76\u4e0d\u5f3a\u76f8\u5173\uff0c\u6709\u6559\u6388\u5c31\u60f3\u7b49\u770b\u5230\u6c60\u5b50\u518d\u51b3\u5b9a\u7684\u60c5\u51b5\u3002
"},{"location":"App/24fall/#college-specific","title":"College-specific\u7f51\u7533\u7684\u5751","text":"CMU\u5982\u679c\u76f4\u63a5\u641c\u7d22 MLT application \u51fa\u73b0\u7684\u4ee5\u4e0b\u9875\u9762\u53ca\u7533\u8bf7\u94fe\u63a5\u662f\u627e\u4e0d\u5230MLT\u9879\u76ee\u7684
Application Management (cmu.edu) \u8fd9\u4e2a\u9875\u9762\u548c\u4ee5\u4e0b\u622a\u56fe\u662f\u6b63\u786e\u7684\uff0c\u540c\u7406mscv\u548cmsaii\u4ec0\u4e48\u7684\u9879\u76ee\u4e5f\u5728\u8fd9\u91cc\u7533\u8bf7\u3002
UWaterloo \u7684\u7533\u8bf7\u5206\u4e3a\u4e24\u4e2a\u9636\u6bb5\uff0c\u7b2c\u4e00\u4e2a\u9636\u6bb5\u8d76\u7d27\u4ea4\u4e86\u624d\u80fd\u5728\u7b2c\u4e8c\u4e2a\u9636\u6bb5\u4e0a\u4f20cv \u6587\u4e66 \u8bed\u8a00\u6210\u7ee9\u7b49\u4e1c\u897f\uff0c\u7b2c\u4e8c\u9636\u6bb5\u7684\u94fe\u63a5\u4f1a\u5728\u7b2c\u4e00\u9636\u6bb5\u540e2-4\u5929\u6536\u5230\u3002\u7b2c\u4e00\u4e2a\u9636\u6bb5\u4e00\u5b9a\u4e00\u5b9a\u8981\u6bd412.1\u63d0\u524d\u81f3\u5c11\u56db\u4e94\u5929\u4ea4
Umich\u7684\u7cfb\u7edf\u4e00\u5f00\u59cb\u56db\u4e94\u4e2a\u9875\u9762\u8981\u987a\u5e8f\u586b\u5b8c\uff0c\u540e\u9762\u7684\u9875\u9762\u624d\u80fd\u8df3\u7740\u586b
"},{"location":"App/24fall/#_5","title":"\u6587\u4e66","text":"\u5176\u5b9e\u6211\u4e2a\u4eba\u8ba4\u4e3a\u5728\u5ba1\u6587\u4e66\u65f6\u6bcf\u4efd\u6587\u4e665-10\u5206\u949f\uff0c\u53ef\u80fd\u6240\u6709\u4eba\u80fd\u4e00\u773c\u770b\u5230\u7684\u662f 1\uff09\u5c0f\u6807\u9898 2\uff09\u52a0\u7c97\u7684\u5173\u952e\u8bcd\u3002\u8bb2\u4e00\u4e2a\u4f8b\u5b50\u662f\u6211\u4e0a\u6b21\u53c2\u52a0\u4e00\u95e8\u8bfe\u7684group tutorial\u65f6\uff0c\u5f53\u65f6\u5c0f\u7ec4\u6210\u5458\u5408\u5199\u4e86\u4e00\u4efdrp\uff0c\u5176\u4e2d\u6211\u5199\u7684\u662f\u6700\u6666\u6da9\u7684lit review\uff0c\u5373\u4e13\u4e1a\u672f\u8bed\u5bc6\u5ea6\u6700\u9ad8\u8fd8\u53e5\u5b50\u6700\u957f\uff0c\u4f46\u662f\u6211\u7ed9\u6bcf\u4e2a\u5206\u4e3b\u9898\u52a0\u4e86\u5c0f\u6807\u9898\uff0c\u5176\u5b83\u540c\u5b66\u5199\u7684\u90e8\u5206\u6ca1\u6709\u52a0\u3002\u8001\u5e08\u5728\u4e0e\u6211\u4eec\u8c08\u8bdd\u7684\u95f4\u9699\u7784\u4e86\u51e0\u773c\u6211\u4eec\u7684\u6587\u4ef6\uff0c\u77ed\u77ed\u7684\u65f6\u95f4\u91cc\u5c31\u53ea\u770b\u8fdb\u53bb\u4e86lit review\u7684\u5c0f\u6807\u9898\uff0c\u70b9\u8bc4\u4e86\u4e00\u4e0b\u3002\u6240\u4ee5\u6211\u89c9\u5f97\u505a\u6e05\u6670\u7684\u5206\u6bb5\u548c\u5c0f\u6807\u9898\u5f88\u91cd\u8981\uff08\u8fd9\u91cc\u771f\u7684\u6709\u70b9\u50cf\u8bbe\u8ba1\u56db\u539f\u5219\uff0c\u5bf9\u6bd4/\u805a\u5408\uff09\uff0c\u5c24\u5176\u662f\u65f6\u95f4\u7cbe\u529b\u4e0d\u591f\u65f6\uff0c\u5176\u4e2d\u7684\u7ec6\u8282\u5185\u5bb9\u8bf4\u4e0d\u5b9a\u4e0d\u7528\u62a0\u592a\u7ec6\u3002
\u60f3\u7ed9\u70b9\u5199\u6587\u4e66\u65f6\u81ea\u5df1\u7528\u7684\u683c\u5f0f
PS\u7ed3\u6784
\u7b2c\u4e00\u6bb5\uff1a\u4e00\u4e9beye-catcher\uff0c\u8bb2\u4e00\u70b9\u5bf9\u81ea\u5df1\u603b\u7ed3\u6027\u7684\u8bdd/tattoo\uff0c\u6216\u8005\u5e72\u8106\u76f4\u63a5\u4ece\u201c\u6211\u672c\u79d1\u5f00\u59cb\u5bf9xxx\u611f\u5174\u8da3\uff0c\u4e8e\u662f\u4e0a\u4e86\u5f88\u591a\u8bfe\u505a\u4e86\u5f88\u591a\u7814\u7a76\u201d\u5e73\u5b9e\u5730\u5f00\u59cb
\u7b2c\u4e8c\u6bb5\uff1a\u4e00\u822c\u4e00\u4e24\u53e5\u8bdd\u5e26\u8fc7\u8bfe\u7a0b\uff0c\u6709\u7279\u522b\u51fa\u8272\u7684score\u6216coursework\u53ef\u4ee5\u5728\u8fd9\u91cc\u8bf4
\u7b2c\u4e09\u5230\u4e94\uff08\u6216\u56db\uff09\u6bb5\uff1a\u6bcf\u6bb5\u4e00\u4e2a\u7ecf\u5386\uff0c\u53ef\u4ee5\u603b\u5206\u603b\u5199\uff0c\u627e\u5230\u4e00\u4e2a\u8fd9\u6bb5\u7ecf\u5386\u6700\u60f3\u7a81\u51fa\u7684\u7279\u70b9/\u54c1\u8d28\uff0c\u7136\u540e\u56f4\u7ed5\u7740\u8bf4
\u7b2c\u516d\u6bb5\uff1amoving forward \u8bb2\u4ee5\u540e\u7684\u89c4\u5212
\u7b2c\u4e03\u6bb5\uff1awhy [program name] and why [school name]
\u7b2c\u516b\u4e5d\u6bb5\uff1a\u5982\u679c\u5b66\u6821\u6709\u7279\u6b8a\u7684diversity \u5956\u5b66\u91d1 gre clarification\u4e4b\u7c7b\u7684\u53ef\u4ee5\u5728\u8fd9\u91cc\u5199
References
SoP\u7ed3\u6784
\u7b2c\u4e00\u6bb5\uff1axxx\u662f\u5f88\u91cd\u8981\u7684\uff0c\u6211\u4e00\u76f4\u5bf9xxx\u611f\u5174\u8da3\uff0c\u6211\u9009\u62e9\u5728x\u6821\u8bfbphd is naturally a continuation of my previous interests and experiences\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u7684\u7814\u7a76\u5174\u8da3\u4e3a\uff1a ( \u6b64\u5904\u53ef\u4ee5\u6709\u5c0f\u6807\u9898\u548c\u4e00\u53e5\u8bdd\u4ecb\u7ecd
\u7b2c\u4e8c\u6bb5\uff1aAAA \u7ed3\u6784\u5982\u4e0b
\u5199\u5b8c\u4e00\u6574\u6bb5\u540e\u6700\u540e\u518d\u8d77\u5c0f\u6807\u9898\n\u4e00\u4e2a\u65b9\u5411\u6709\u591a\u91cd\u8981\u7b80\u4ecb\n\uff08+\u81ea\u5df1\u8fc7\u53bb\u8bfe\u7a0b\u9879\u76ee\uff0c\u5982\u679c\u771f\u7684\u5f88\u91cd\u8981\u7684\u8bdd\u5427\uff09\n+\u81ea\u5df1\u8fc7\u53bb\u7814\u7a76\n+\u81ea\u5df1\u8fc7\u53bb\u7814\u7a76\n+\u672a\u6765\u7814\u7a76\n+\u672a\u6765\u7814\u7a76\n+\u5e0c\u671bachieve\u7684\u76ee\u6807\n
\u7b2c\u4e09\u6bb5\uff1aBBB \u540c\u4e0a
\u7b2c\u56db\u6bb5\uff1aCCC \u540c\u4e0a\u4e0a
\u7b2c\u4e94\u6bb5\uff1aMoving forward
\u7b2c\u516d\u6bb5\uff1awhy [program name] and why [school name]
References
\u6211\u7684\u8fc7\u53bb\u7814\u7a76\u7ecf\u5386\u4e0e\u6211\u672a\u6765\u7684\u76ee\u6807\u65b9\u5411\u7279\u522b\u4e0d\u76f8\u4f3c\uff0c\u4f46\u662f\u611f\u89c9\u4f60\u5fc5\u987b\u53bb\u5bfb\u627e\u4e00\u4e2a\u5e73\u8861\u70b9\uff0c\u5bfb\u627e\u4e24\u4e09\u4e2a\u5c0f\u6807\u9898\u80fd\u628a\u4ed6\u4eec\u90fd\u6982\u62ec\u4f4f\u3002\u8fd9\u4e24\u4e09\u4e2a\u5c0f\u6807\u9898\u9996\u5148\u8981\u670d\u52a1\u4e8e\u672a\u6765\u65b9\u5411\uff0c\u7136\u540e\u56e0\u4e3a\u4f60\u8fc7\u53bb\u7684\u6bcf\u4e2a\u9879\u76ee\u4e0d\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u5c5e\u6027/\u9886\u57df\uff0c\u53ef\u4ee5\u9009\u62e9\u80fd\u591f\u670d\u52a1\u4e8e\u672a\u6765\u65b9\u5411\u7684\u65b9\u9762\uff0c\u7528\u201c\u6211\u53d7\u5230\u4e86xx\u65b9\u9762\u7684\u542f\u53d1\u201d\u4e4b\u7c7b\u7684\u8bdd\u8fde\u63a5\u8d77\u6765\u3002
UCSD \u7ed9\u7684\u53c2\u8003\u6307\u5bfc \u4e94\u4e2a\u95ee\u9898 - How did you become interested in this field? - What experiences have contributed toward your preparation for further study in this field? - What are your future goals? - What are your research interests? - How are you a \"match\" for the program to which you are applying? \u5176\u5b83\u8981\u6ce8\u610f\u7684 - Give examples of personal attributes or qualities that would help you complete graduate study successfully. - Describe your determination to achieve your goals, your initiative and ability to develop ideas, and your ability to work independently. - Describe background characteristics that may have placed you at an educational disadvantage (English language learner, family economic history, lack of educational opportunity, disability, etc.). - Leave the reader believing that you are prepared for advanced academic work and will be successful in graduate school.
"},{"location":"App/24fall/#_6","title":"\u81f4\u8c22","text":"\u6211\u7684\u63a8\u8350\u4eba
\u7ed9\u8fc7\u6211\u91cd\u8981\u4eba\u751f\u5efa\u8bae\u7684
\u8001\u5e08
\u8ddf\u6211\u804a\u7533\u8bf7\u7684\u540c\u5b66
\u63d0\u4f9b\u60c5\u611f\u652f\u6301\u7684\u540c\u5b66\u548cTA\u4eec
"},{"location":"App/24fall/#emotion-timeline","title":"\u9644\u5f55\uff1aEmotion \u7248 \u6211\u7684 Timeline\uff08\u5efa\u8bae\u522b\u770b \u770b\u6211\u4e22\u4eba\uff09","text":"\u6211\u7684\u7533\u8bf7\u771f\u7684\u597d\u6781\u9650\u554a\u554a\u554a\u554a\u554a\u554a\u554a
"},{"location":"App/nlp_phd/","title":"NLP Global PHD Equality Digest (\u642c\u8fd0)","text":"\u7ffb\u8bd1\u81eahttps://github.com/zhijing-jin/nlp-phd-global-equality
"},{"location":"App/nlp_phd/#_1","title":"\u9996\u63a8\u8d44\u6e90","text":"(John Hewitt, PhD@Stanford)\u00a0Undergrad to PhD, or not - advice for undergrads interested in research\u00a0(2018). [Suggestions]
\u7a77\u548c\u4e0d\u806a\u660e\u4e0d\u662f\u7406\u7531
\u7533\u8bf7\u524d\u76848\u6708\u52309\u6708\u8981\u5199\u597d\u81ea\u5df1\u7684SOP\uff0c\u601d\u8003\u81ea\u5df1\u8981\u505a\u600e\u6837\u7684\u7814\u7a76\uff0c\u600e\u6837\u8ba9\u81ea\u5df1\u7684\u7814\u7a76\u6709\u5f71\u54cd\u529b\u3002\u57288\u6708\u8981\u8054\u7cfb\u597d\u63a8\u8350\u4fe1
(Prof Jason Eisner@JHU)\u00a0Advice for Research Students\u00a0(last updated: 2021). [List of suggestions]
Interesting snippets: \"Goal-driven. Develop a vision of some new AI capabilities you\u2019d like to achieve, and solve problems that bring you closer to that goal.\", \"If you are working on incremental ideas, be aware that their usefulness depends on their complexity.\", \"Consider how the biggests bursts of impactful work tend to be tightly clustered in a small number of research groups and institutions. That\u2019s not because these people are dramatically smarter than everyone else, it\u2019s because they have a higher density of expertise and perspective, which puts them a little ahead of the rest of the community, and thus they dominate in generating new results.\", \"Early on in your career, I recommend splitting your time about evenly between textbooks and papers. You should choose a small set of relevant textbooks and theses to gradually work through, and you should also reimplement the models and algorithms from your favorite papers.\" 3. (Prof Fei-Fei Li@Stanford)\u00a0De-Mystifying Good Research and Good Papers\u00a0(2014). [Suggestions]
Interesting snippets: \"This means publishing papers is NOT about \u201cthis has not been published or written before, let me do it\u201d, nor is it about \u201clet me find an arcane little problem that can get me an easy poster\u201d. It\u2019s about \u201cif I do this, I could offer a better solution to this important problem,\u201d or \u201cif I do this, I could add a genuinely new and important piece of knowledge to the field.\u201d You should always conduct research with the goal that it could be directly used by many people (or industry). In other words, your research topic should have many \u2018customers\u2019, and your solution would be the one they want to use. A good research project is not about the past (i.e. obtaining a higher performance than the previous N papers). It\u2019s\u00a0about the future (i.e. inspiring N future papers to follow and cite you, N->\\inf).\"
"},{"location":"App/nlp_phd/#_10","title":"\u8bfb\u6587\u7ae0\u7684\u5de5\u5177","text":"\u672a\u5b8c\u5f85\u7eed\uff1a
"},{"location":"App/nlp_phd/#_13","title":"\u7b2c\u4e09\u9636\u6bb5\uff1a\u5de5\u4e1a\u754c\u7814\u7a76\u8005\u7684\u751f\u6d3b","text":""},{"location":"App/nlp_phd/#_14","title":"\u7b2c\u56db\u9636\u6bb5\uff1a\u5982\u4f55\u83b7\u5f97\u6559\u804c\uff1f\u5982\u4f55\u505a\u4e00\u4e2a\u597d\u5bfc\u5e08\uff1f","text":""},{"location":"App/nlp_phd/#nlp","title":"\u7b2c\u4e94\u9636\u6bb5\uff1a\u89c4\u5212NLP\u7684\u7814\u7a76\u751f\u6daf","text":""},{"location":"App/nlp_phd/#_15","title":"\u4e86\u89e3\u66f4\u591a","text":""},{"location":"App/nlp_phd/#_16","title":"\u5f15\u7528","text":"@misc{resources2021jin,\n author = {Zhijing Jin},\n title = {Resources to Help Global Equality for PhDs in NLP},\n year = {2021},\n publisher = {GitHub},\n journal = {GitHub repository},\n howpublished = {\\url{https://github.com/zhijing-jin/nlp-phd-global-equality}}\n}\n
"},{"location":"App/zju_ling_cs/","title":"ZJU English Major to CS&NLP","text":"\u26a0\ufe0f \u611f\u89c9\u5f53\u65f6\u5199\u5f97\u4e0d\u662f\u5f88\u597d\uff0c\u73b0\u5728\u5f88\u591a\u89c2\u5ff5\u53c8\u6709\u4e9b\u6539\u53d8\uff0c\u53ef\u80fd24\u5e74\u6625\u8282\u671f\u95f4\u7a7a\u4e0b\u6765\u4f1a\u518d\u8ba4\u771f\u6539\u4e00\u4e0borz
"},{"location":"App/zju_ling_cs/#_1","title":"\u672c\u6587\u6863\u662f\u4ec0\u4e48\uff1f","text":"\u7b14\u8005\u8f6c\u4e13\u4e1a\u8e29\u8fc7\u7684\u5751\u548c\u5bf9\u540e\u8f88\u7684\u5efa\u8bae\uff0c\u771f\u5fc3\u60f3\u5efa\u7acb\u8d77ZJU\u5185\u90e8\u826f\u597d\u7684\u4f20\u5e2e\u5e26\u6c1b\u56f4\u3002
"},{"location":"App/zju_ling_cs/#_2","title":"\u89c2\u5ff5&\u4e60\u60ef\u95ee\u9898","text":"\u5728\u5177\u4f53\u5efa\u8bae\u524d\u9996\u5148\u56de\u7b54\u4e00\u4e9b\u5e38\u6709\u7684\u62c5\u5fe7+\u505a\u4e00\u4e9b\u4e60\u60ef\u65b9\u9762\u7684\u63d0\u9192
"},{"location":"App/zju_ling_cs/#cs","title":"\u6211\u80fd\u8f6c\u5230CS\u5417\uff1f","text":"\u80fd\u3002\u6709\u5982\u4e0b\u6848\u4f8b\uff08\u4e0d\u4ee3\u8868\u6240\u6709\u4eba\u613f\u610f\u88ab\u8054\u7cfb\u5230\uff0c\u4e0d\u4fdd\u8bc1\u63d0\u4f9b\u8054\u7cfb\u65b9\u5f0f\uff09
\u60f3\u8c61\u4e00\u4e2a\u7b80\u5386 \u80fd\u5728\u7b80\u5386\u4e0a\u5f88\u663e\u773c\u548c\u4e00\u4e2a\u77ed\u8bed\u4ee5\u5185\u80fd\u8868\u8ff0\u7684\u7ecf\u5386\uff0c\u624d\u8981\u52aa\u529b\u53bb\u5237\u3002 \u6bd4\u5982\u76f8\u6bd4\u4e8e\u201c\u53cc\u4e13\u4e1a\uff0c\u662f\u4e00\u4e2azju\u7279\u6709\u7684\u8f85\u4fee\uff0c\u4e0d\u6c34\u7684\uff0c\u5b83\u8981\u6c42\u7684\u8bfe\u6bd4\u8f85\u4fee\u591a\uff0c\u4f8b\u5982\u6211\u4fee\u4e86xxx\uff0c\u6211\u53ea\u662f\u6ca1\u4feexxx\u201d\u548c\u201c\u4fee\u4e86\u4e00\u534aCS\u8bfe\u4e00\u534aAI\u8bfe\u201d\uff0c\u201cCS\u53cc\u5b66\u4f4d\u201d\u5c31\u66f4\u9002\u5408\u51fa\u73b0\u5728\u7b80\u5386\u4e0a\u3002
\u505a\u91cd\u5927\u51b3\u5b9a\u65f6\uff0c\u81f3\u5c11\u54a8\u8be220\u4e2a\u4eba\u7684\u5efa\u8bae\uff0c\u8981\u4e48\u54a8\u8be2\u4e86\u89e3n\u4e2a\u4eba\u5efa\u8bae\u7684\u4eba\uff08\u6bd4\u5982\u76f8\u5e94\u884c\u4e1a\u7684\u4eb2\u4eba\u670b\u53cb\u3001\u5b66\u751f\u5f88\u591a\u7684\u8001\u5e08\uff09\u6765\u62b5n\u4e2a\u4eba\uff0c\u603b\u4e4b\u603b\u548c\u8981\u62ff\u523020\u4e2a\u4eba\u5de6\u53f3\u7684\u5efa\u8bae\u3002
\u4e0d\u662f\u7684\u3002 - \u7406\u8bba\u4e0a\u662f\u5b8c\u5168\u53ef\u4ee5\u5b66\u597d\u7684\u3002NLP\u5708\u6709\u5f88\u591a\u7814\u7a76\u8005\u8bfb\u8fc7\u8bed\u8a00\u5b66\u548cCS\u53cc\u672c\u79d1\uff0c\u4ee3\u8868AP\u6709AllenNLP Noah Smitch, Colimbia University Zhou Yu\uff08ZJU\u7684\u672c\u79d1\uff09. \u8bfb\u8bed\u8a00\u5b66\u6ca1\u6709\u803d\u8bef\u4ed6\u4eec\u7684\u8111\u5b50\uff0c\u53cd\u800c\u662f\u4e00\u4e2a\u5f88\u597d\u7684idea\u6765\u6e90\u3002\u6211\u611f\u89c9\u6709\u5f88\u591a\u5929\u624d\u7684\u6848\u4f8b\u53ef\u4ee5\u8bc1\u660e\u4eba\u7684\u77e5\u8bc6\u5bb9\u91cf\u548c\u5b66\u4e60\u80fd\u529b\u4e0a\u9650\u662f\u8d85\u51fa\u5927\u5bb6\u60f3\u8c61\u7684\uff0c\u5b66\u4e24\u4e2a\u4e13\u4e1a\u8fd9\u4ef6\u5c0f\u4e8b\u8fdc\u8fdc\u5728\u8fd9\u4e2a\u4e0a\u9650\u4e4b\u4e0b\u3002\u6211\u6c38\u8fdc\u8ba4\u4e3a\u6bc5\u529b\u548c\uff08\u5bf9\u81ea\u5df1\u4eba\u751f\u4e0a\u9650\u7684\uff09\u60f3\u8c61\u529b\u6bd4\u5f53\u524d\u80fd\u529b\u66f4\u6709\u51b3\u5b9a\u4f5c\u7528\u3002 - \u5b9e\u9645\u82f1\u8bed\u4e13\u4e1a\u53bbCS\u53cc\u4e13\u4e1a\u5bb9\u6613\u5403\u4f4e\u7ee9\u70b9\u7684\u539f\u56e0\uff0c\u5f80\u5f80\u4e0d\u662f\u80fd\u529b\u667a\u529b\u4e0d\u8db3\uff0c\u800c\u662f\u6709\u4fe1\u606f\u5dee\uff1a\u751f\u6d3b\u5728\u6587\u79d1\u7684\u6563\u6f2b\u73af\u5883\u4e2d\u96be\u4ee5\u77e5\u9053\u5927\u90e8\u5206\u540c\u5b66\u7684\u81ea\u5b66\u8fdb\u5ea6\uff0c\u548c\u5982\u679c\u67d0\u4e9b\u8bfe\u7a0b\u6709\u5b9e\u8df5\u4e0a\u7684\u5751\uff0c\u6ca1\u6709\u4e0e\u5927\u90e8\u961f\u4e00\u8d77\u5b66\u4e60\u7684\u540c\u5b66\u5c31\u96be\u4ee5\u77e5\u9053\u600e\u6837\u7075\u6d3b\u5e94\u5bf9\u3002\u6240\u4ee5\u5efa\u8bae\u4e0e\u540c\u5b66\u4e00\u8d77\u5b66\u4e60\uff0c\u53c2\u89c1\u4e0b\u4e00\u6761\u3002
"},{"location":"App/zju_ling_cs/#cscs","title":"\u8981\u62e5\u6709\u4e00\u4e2a\u6216\u51e0\u4e2a\u540c\u6837\u8de8\u4e13\u4e1a\u5b66CS\u7684\u670b\u53cb\uff0c\u6216\u76f4\u63a5\u878d\u5165\u540c\u4e00\u7ea7\u7684CS\u672c\u79d1\u751f\u5708\u5b50\u91cc\u3002\u5982\u679c\u5b9e\u5728\u6ca1\u6709\uff0c\u4e00\u4e9b\u5176\u5b83\u5de5\u79d1\u7684\u540c\u5b66\u4e5f\u53ef\u4ee5\u3002","text":"\u540c\u5b66\u7684\u7528\u5904\u6709\uff1a - \u5e2e\u52a9\u4f60\u8ddf\u4e0a\u5b66\u4e60\u8282\u594f\u3002CS\u7684\u751f\u6d3b\u8282\u594f\u662f\u82f1\u8bed\u4e13\u4e1a\u76842\u500d\uff0c\u662f\u7406\u79d1\u4e13\u4e1a\u76841.5\u500d\uff0c\u5982\u679c\u51b3\u5b9a\u8f6c\u4e13\u4e1a\u662f\u9700\u8981\u4e3b\u52a8\u63d0\u9ad8\u4e00\u4e0b\u751f\u6d3b\u8282\u594f\u7684\uff0c\u505a\u4e8b\u79ef\u6781\u4e00\u70b9\uff0c\u544a\u522b\u62d6\u5ef6\u3002 - \u4e92\u76f8\u63a8\u8350\u597d\u7684\u81ea\u5b66\u8d44\u6599\uff0c\u4e92\u76f8\u5206\u4eab\u7b14\u8bb0\u548c\u8ba8\u8bba\u9898\u76ee\uff0c\u5206\u5de5\u6574\u7406\u671f\u672b\u590d\u4e60\u8d44\u6599\uff0c\u671f\u672b\u4e92\u76f8\u63d0\u95ee\uff0c\u5f62\u6210\u81ea\u5b66\u6c1b\u56f4\uff0c\u8282\u7701\u4e00\u4e9b\u8e29\u5751\u65f6\u95f4\u3002 - \u5982\u679c\u67d0\u4e9b\u8bfe\u7a0b\u5b89\u6392\u6709\u6559\u5b66\u4e8b\u6545\uff0c\u4f60\u53ef\u4ee5\u53ca\u65f6\u77e5\u9053\u5927\u90e8\u5206\u540c\u5b66\u662f\u600e\u6837\u5e94\u5bf9\u7684\uff0c\u53ca\u65f6\u8c03\u6574\u81ea\u5df1\u7684\u5e94\u5bf9\u63aa\u65bd\uff0c\u9632\u6b62\u5982\u679c\u6210\u7ee9\u5360\u6bd4\u7a81\u7136\u8c03\u6574\uff0c\u81ea\u5df1\u5c06\u52aa\u529b\u82b1\u5728\u4e86\u6700\u540e\u5360\u6210\u7ee9\u6bd4\u91cd\u5f88\u5c0f\u7684\u5730\u65b9\u3002
"},{"location":"App/zju_ling_cs/#_5","title":"\u8981\u591a\u8bb0\u7b14\u8bb0","text":"\u8bb0\u7b14\u8bb0\u662f\u8d39\u66fc\u5b66\u4e60\u6cd5\u7684\u6295\u5165\u4ea7\u51fa\u6bd4\u6700\u9ad8\u7684\u5b9e\u8df5\u5f62\u5f0f\uff0c\u5373\u65e2\u5e2e\u52a9\u68c0\u67e5\u7406\u89e3\uff0c\u7b14\u8bb0\u53c8\u9020\u798f\u540e\u4eba\u3002\u4f60\u53ef\u4ee5\u79c9\u627f\u5f00\u6e90\u7cbe\u795e\uff0c\u50cf\u524d\u8f88\u4e00\u6837\u591a\u5c06\u7b14\u8bb0\u516c\u5e03\u9020\u798f\u540e\u4eba\uff08\u4e0d\u8fc7\u8bf7\u9075\u5b88\u8bda\u4fe1\u5b88\u5219\uff09\u3002\u975e\u5e38\u5e0c\u671bZJU\u80fd\u9010\u6e10\u5f62\u6210\u8f83\u597d\u7684\u4f20\u5e2e\u5e26\u6c1b\u56f4\uff0c\u8ba9\u540e\u8f88\u4e5f\u6709\u826f\u597d\u6821\u53cb\u8d44\u6e90\u53ef\u4eab\u7528\u3002
"},{"location":"App/zju_ling_cs/#_6","title":"\u6211\u53ef\u4ee5\u4ee5\u600e\u6837\u7684\u8eab\u4efd\u672c\u79d1\u6bd5\u4e1a\uff1f\u6211\u6709\u54ea\u4e9b\u53ef\u884c\u7684\u51fa\u8def\uff1f","text":"\u4ee5\u4e0b\u8fd9\u4e9b\u90fd\u662f\u53ef\u80fd\u505a\u5230\u7684\uff0c\u6211\u4e5f\u5206\u522b\u5217\u51fa\u4e86\u6211\u8ba4\u4e3a\u9700\u8981\u51c6\u5907\u7684\u80cc\u666f\u3002 - \u51fa\u56fdms\uff1a\u7ee9\u70b9\uff0c\u6691\u7814/\u5b9e\u4e60 - \u51fa\u56fd\u76f4\u63a5phd\uff1a\u6691\u7814\uff0cpaper - \u672c\u6821\u76f4\u535a\uff1a\u7ee9\u70b9\uff0c\u8fdb\u672c\u6821\u7ec4\uff0c\u590f\u4ee4\u8425\uff0cpaper - \u8de8\u6821\u76f4\u535a\uff1a\u7ee9\u70b9\uff0c\u5bf9\u65b9\u6821\u590f\u4ee4\u8425\uff0cpaper - \u5de5\u4f5c\uff1a\u5237\u9898\uff0c\u5b9e\u4e60 \u5176\u4e2d\u6211\u8ba4\u4e3a\u503c\u5f97\u6ce8\u610f\u7684\u8fd8\u6709\uff0c\u5177\u4f53\u6700\u597d\u7531\u8bfb\u8005\u518d\u54a8\u8be2\u76f8\u5e94\u8eab\u4efd\u7684\u4eba\u7684\u5efa\u8bae\u3002\u672c\u6761\u9002\u7528\u524d\u9762\u6240\u8ff0\u201c20\u4e2a\u4eba\u5efa\u8bae\u201d\u51c6\u5219\u3002
"},{"location":"App/zju_ling_cs/#_7","title":"\u8bfe\u7a0b","text":""},{"location":"App/zju_ling_cs/#cs_4","title":"CS\u5fc5\u4fee\u8bfe","text":"\u9996\u5148\u8981\u660e\u786e\u4e00\u4e2a\u8ba4\u77e5\u95ee\u9898\uff1a\u8bfbCS\u53cc\u5b66\u4f4d\u662f\u4e00\u4e2a\u539f\u5b50\u6027\u7684\u4e8b\u52a1\uff0c\u8981\u4e48\u4e0d\u8bfb\uff0c\u8981\u4e48\u6309\u9700\u6c42\u8bfb\u5b8c\u6216\u8f85\u4fee\u6216\u53cc\u5b66\u4f4d\uff0c\u8fd9\u4e24\u79cd\u9009\u62e9\u90fd\u662f\u6295\u5165\u4ea7\u51fa\u6bd4\u8f83\u9ad8\u7684\uff1b\u6295\u5165\u4ea7\u51fa\u6bd4\u6700\u4f4e\u7684\u662f\u8bfb\u4e00\u534a\uff08\u5fae\u8f85\u4fee\u6216\u53cc\u4e13\u4e1a\uff09\u3002 \u8be5\u56fe\u4e2d\u9664\u6570\u7406\u57fa\u7840\u6a21\u5757\u4e0d\u662f\u53cc\u5b66\u4f4d\u5fc5\u4fee\uff0c\u5176\u5b83\u662f\u5fc5\u4fee\u3002 \uff08\u8fd9\u4e2a\u56fe\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u6709\u4e2a\u7ea2\u5708\uff0c\u627e\u4e0d\u5230\u539f\u56fe\u4e86\uff0c\u6279\u8bc4cyh\u540c\u5b66\u4e71\u753b\uff09
\u9009\u4e0d\u4e0aCS\u7684\u8bfe\u600e\u4e48\u529e\uff1f - \u6700\u6709\u6548\uff1a\u8865\u9009+\u5728\u8865\u9009\u7684\u51e0\u5929\u91cc\u7ebf\u4e0b\u53bb\u9009\u8bfe\u529e\u6216\u7ed9\u9009\u8bfe\u529e\u53d1\u90ae\u4ef6\u3002\u674e\u6653\u8001\u5e08\u548c\u5f20\u4f20\u534e\u8001\u5e08\u90fd\u5f88nice\uff0c\u8868\u793a\u81ea\u5df1\u5f88\u60f3\u9009\u8bfe\uff0c\u8ddf\u8001\u5e08\u8bf4\u660e\u539f\u56e0\u3002 - \u7b2c\u4e8c\u6709\u6548\uff1a\u5982\u679c\u4efb\u8bfe\u8001\u5e08\u5728\u8ba1\u9662\u8bdd\u8bed\u6743\u8f83\u5927\uff0c\u8bf7\u4efb\u8bfe\u8001\u5e08\u5e2e\u5fd9\u8ddf\u9009\u8bfe\u529e\u8bf4\uff0c\u80fd\u4fdd\u8bc1\u4f60\u9009\u4e0a\u8be5\u8001\u5e08\u7684\u8bfe\u3002 - \u7b2c\u4e09\u6709\u6548\uff1a\u9009\u8bfe\u65f6\u4e0eCS\u7684\u540c\u5b66\u5546\u91cf\uff0c\u505a\u51fa\u65f6\u95f4\u6b63\u597d\u7684\u4e00\u4e9b\u8bfe\u8868\u3002\u53ef\u80fd\u6d89\u53ca\u5230\u201c\u7528\u4e00\u4e9b\u8bfe\u5835\u4f4f\u53e6\u4e00\u4e9b\u8bfe\u201d\u8fd9\u79cd\u590d\u6742\u64cd\u4f5c\uff0c\u6240\u4ee5\u5408\u4f5c\u6bd4\u8f83\u5212\u7b97\u3002
\u600e\u4e48\u5b66\uff1f - ZJU\u8bfe\u7a0b\u5171\u4eab\u8ba1\u5212 https://github.com/QSCTech/zju-icicles - \u56fe\u7075\u73ed\u8bfe\u7a0b\u901f\u901a\u8ba1\u5212 https://github.com/ZJU-Turing/TuringCourses - \u4e00\u4f4d\u5b66\u957f\u7684\u4f18\u8d28\u7b14\u8bb0 \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4\uff01 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io) - \u4e00\u4f4d\u5b66\u957f\u7684\u4f18\u8d28\u7b14\u8bb0 https://github.com/Zhang-Each/CourseNoteOfZJUSE
"},{"location":"App/zju_ling_cs/#ai","title":"AI","text":"AI\u8bfe\u4e00\u822c\u6bd4CS\u8bfe\u597d\u9009\uff0c\u4f46\u662f\u5982\u679c\u9009\u4e0d\u4e0a\u4e5f\u8bf7\u9075\u7167\u4e0a\u6761\u4e2d\u7684\u5efa\u8bae\u3002 \u975e\u5fc5\u8981\u4e0d\u9009AI\u8bfe\uff0cAI\u8bfe\u6700\u5927\u7684\u6536\u83b7\u662f\u5728\u7b80\u5386\u4e0a\u4f5c\u4e3a\u4e00\u4e2a90+\u8bfe\u7a0b\u51fa\u73b0\uff0c\u57fa\u672c\u5b66\u4e0d\u5230\u4e1c\u897f\uff08\u9664\u4e86NLP\u8bfe\u6211\u611f\u89c9\u542c\u8bfe\u6536\u83b7\u633a\u5927\u7684\uff09\uff0c\u4e3b\u8981\u9760\u81ea\u5b66\u540e\u5377\u51fa\u5927\u4f5c\u4e1a\u3002
"},{"location":"App/zju_ling_cs/#_8","title":"\u8bed\u8a00\u5b66","text":"\u56e0\u4e3a\u82f1\u4e13\u57f9\u517b\u65b9\u6848\u8fd8\u662f\u8981\u6c42\u4fee\u5927\u91cf\u4e13\u4e1a\u8bfe\u7684\uff0c\u611f\u89c9\u53ef\u4ee5\u5c3d\u91cf\u628a\u8bed\u8a00\u5b66\u6a21\u5757\u591a\u4fee\u4e00\u70b9\uff0c\u6709\u4e9b\u5728\u8fdb\u7ec4\u7684\u65f6\u5019\u53ef\u80fd\u8fd8\u662f\u8ba4\u53ef\u7684\u3002 \u4ee5\u4e0b\u8bfe\u7a0b\u5982\u679c\u62ff\u4e86\u9ad8\u5206\u503c\u5f97\u5728\u7b80\u5386\u4e0a\u4e00\u63d0 - \u5f53\u4ee3\u8bed\u8a00\u5b66 - \u8bed\u97f3\u5b66 - \u53e5\u6cd5\u5b66 - \u5fc3\u7406\u8bed\u8a00\u5b66 - \u8bed\u4e49\u5b66 - \u8bed\u7528\u5b66 - \u8bed\u6599\u5e93\u8bed\u8a00\u5b66
"},{"location":"App/zju_ling_cs/#_9","title":"\u6570\u5b66","text":"\u5bf9\u4e8ePhD\u3001\u627e\u5de5\u548c\u56fd\u5185\u76f4\u535a\uff1a \u53ef\u80fd\u4e0d\u9700\u8981\u6570\u5b66\u3002\u3002\u3002\u8ba4\u4e3a\u6700\u597d\u4e0d\u8981\u989d\u5916\u9009\u6570\u5b66\u8bfe \u6211\u81f3\u4eca\u9047\u5230\u7684\u8001\u5e08\u6ca1\u6709\u56e0\u4e3a\u6211\u7b80\u5386\u4e0a\u4efb\u4f55\u6570\u5b66\u76f8\u5173\u7684\u4e1c\u897f\u800c\u5f55\u6211\u6216\u62d2\u6211\u7684\uff0c\u90fd\u662f\u53ea\u95ee\u7f16\u7a0b\u3002 CS\u4e13\u4e1a\u8bfe\u91cc\u7684\u79bb\u6563\u6570\u5b66\u548c\u8ba1\u7b97\u7406\u8bba\uff08\u548c\u53ef\u80fd\u8fd8\u6709\u6570\u903b\uff09\u5df2\u7ecf\u8db3\u591f\u57f9\u517b\u6570\u5b66\u601d\u7ef4\u3002 \u5982\u679c\u62c5\u5fc3\u6570\u636e\u5206\u6790\u548c\u7edf\u8ba1\u6280\u80fd\uff0c\u6587\u6570\u91cc\u636e\u8bf4\u5e94\u7528\u7edf\u8ba1\u5b66\u8fd9\u95e8\u8bfe\u7a0b\u6bd4\u9ad8\u7b49\u6570\u5b66\u597d\u4f7f\uff0c\u8fd8\u6709\u673a\u4f1a\u7684\u540c\u5b66\u53ef\u4ee5\u8bd5\u4e00\u4e0b\u3002
\u5bf9\u4e8ems\uff1a \u786e\u5b9e\u6709\u4e00\u4e9b\u9879\u76ee\u8981\u6c42\u4fee\u8fc7\u4e00\u4e9b\u6570\u5b66\u8bfe\u7a0b\uff0c\u4f8b\u5982\u521a\u770b\u5230SUTD\u7684ISTD ms\u8981\u6c42\u4e24\u5b66\u671f\u5fae\u79ef\u5206\uff0c\u4e00\u5b66\u671f\u7ebf\u4ee3\u548c\u4e00\u5b66\u671f\u6982\u7edf\uff0c\u8fd9\u79cd\u65e0\u7591\u662f\u6bd4\u8f83\u4e0d\u53cb\u597d\u7684\u9879\u76ee\u4e86\u3002 \u4e5f\u6709\u6bd4\u8f83\u53cb\u597d\u7684\u9879\u76ee\uff0c\u5317\u7f8e\u4e00\u4e9b0\u57fa\u7840\u8f6c\u7801\u9879\u76ee\u53ef\u53c2\u7167OpenCSapp\uff0c\u82f1\u56fd\u7684IC\u548cUCL\u5728\u524d\u5e74\u4e5f\u5f00\u4e86\u96f6\u57fa\u7840\u8f6c\u7801\u9879\u76ee\uff0c\u4e0d\u8fc7\u51fa\u8def\u548c\u542b\u91d1\u91cf\u9700\u8981\u81ea\u5df1\u8861\u91cf\uff0c\u8fd8\u662f\u5efa\u8bae\u201c\u54a8\u8be220\u4e2a\u4eba\u201d\u51c6\u5219\u3002\u4ee3\u8868dp\u662f18\u7ea7SJTU\u82f1\u8bed\u4e13\u4e1a\uff0c4\u6bb5\u79d1\u7814\u6216\u4e92\u8054\u7f51\u5382NLP\u4ea7\u54c1\u5b9e\u4e60\uff0c\u5c11\u91cf\u9ad8\u5206\u6570\u5b66\u548c\u7f16\u7a0b\u8bfe\u7a0b\uff0c\u7ee9\u70b990+ \u2192 IC CS ms
"},{"location":"App/zju_ling_cs/#_10","title":"\u7ee9\u70b9","text":"\u53c2\u7167\u8fd9\u4e9b\u9876\u4f1a\u90fd\u6709\u4ec0\u4e48track\uff0c\u4e0b\u9762\u662f\u6700\u8fd1\u4e00\u671f\u6bcf\u4e2atrack\u7684best paper - Best Papers - ACL 2023 (aclweb.org) - Best Paper Awards - emnlp 2022 (balhafni.github.io) - Transactions of the Association for Computational Linguistics (transacl.org) - Announcing the NAACL 2022 Best Paper Awards! - NAACL-HLT 2022
\u7279\u522b\u5730\uff0c\u60f3\u5230NLP\u91cc\u6bd4\u8f83\u7eaf\u8bed\u8a00\u5b66\u7684\u4e3b\u9898/\u65b9\u6cd5\u4e5f\u6709\u4e00\u4e9b\uff0c\u6709\u5982\u4e0b\u51e0\u4e2a \u4e3a\u4ec0\u4e48\u8981\u8bb2\u8fd9\u4e00\u5757\u56e0\u4e3a\u62c5\u5fc3\u4f60\u5728\u9762\u8bd5\u7684\u65f6\u5019\u4f1a\u9700\u8981\u5411\u8001\u5e08\u8bc1\u660e\u4f60\u7684\u53e6\u4e00\u90e8\u5206\u4e13\u4e1a\u77e5\u8bc6\u4e5f\u662f\u6709\u7528\u7684 \u4e00\u822c\u6b27\u6d32\u7684NLP\u4f1a\u504f\u8bed\u8a00\u5b66\u4e00\u70b9 - \u5b9e\u9a8c\u8bed\u97f3\u548c\u97f3\u7cfb\u5b66 - \u7528\u8bed\u8a00\u5b66\u77e5\u8bc6\u505a\u6570\u636e\u548c\u6570\u636e\u589e\u5f3a - AI\u4e2d\u7684\u4f26\u7406\u9053\u5fb7\u95ee\u9898 - \u7a00\u6709\u8bed\u8a00\u6316\u6398
"},{"location":"App/zju_ling_cs/#_12","title":"\u5982\u4f55\u9009\u5bfc\uff1f","text":"\u56fd\u5916\u5bfc\u5e08\uff1a\u5e38\u8bfb\u6bcf\u5e74\u7684\u9876\u4f1a\u6709\u610f\u601d\u8bba\u6587\uff0c\u5e76\u53c2\u7167CSRankings: Computer Science Rankings\uff0c\u5173\u6ce8\u5b66\u672f\u5708\u517b\u597d\u53f7\u540e\u5e38\u5237Twitter \u56fd\u5185\u6821\u5185\u5bfc\u5e08\uff1a\u5982\u679c\u6709\u60f3\u8be2\u95ee\u7684\u5bfc\u5e08\u540d\u5355\u53ef\u4ee5\u90ae\u4ef6\u95ee\u6211 \u9009\u5bfc\u6216\u8005\u8054\u7cfbPhD\u7684\u65f6\u5019\u5982\u679c\u63a5\u5230\u7684\u4efb\u52a1\u662f\u4e8c\u4f5c\u4e09\u4f5c\u5f80\u540e\uff0c\u5f88\u53ef\u80fd\u662f\u6253\u767d\u5de5\uff0c\u57fa\u672c\u53ef\u4ee5\u62d2\u7edd\u3002\u9664\u975e\u4f60\u8ba4\u4e3a\u4f60\u627f\u62c5\u7684\u5de5\u4f5c\u8f83\u4e3a\u91cd\u8981\uff0c\u8001\u5e08\u53ef\u4ee5\u7ed9\u4f60\u63a8\u8350\u4fe1\uff0c\u4e8c\u4f5c\u4e09\u4f5c\u7684\u4f5c\u7528\u53ef\u80fd\u6ca1\u6709\u63a8\u8350\u4fe1\u5927\u3002 \u5982\u679c\u7533\u8bf7PhD\uff0c\u63a8\u8350\u4fe1\u7684\u529b\u5ea6\uff1a\u4f60\u4e0e\u63a8\u8350\u4eba\u7684\u4ea7\u51fa\u5f88\u91cd\u8981+\u76ee\u6807PhD\u5bfc\u8ba4\u8bc6\u7684\u4eba > \u4f60\u4e0e\u63a8\u8350\u4eba\u7684\u4ea7\u51fa\u5f88\u91cd\u8981+\u76ee\u6807PhD\u5bfc\u4e0d\u8ba4\u8bc6\u7684\u4eba > \u5176\u5b83
"},{"location":"App/zju_ling_cs/#_13","title":"\u7533\u8bf7","text":"\u56e0\u4e3a\u4fdd\u7814\u548c\u627e\u5de5\u6211\u786e\u5b9e\u4e0d\u61c2\uff0c\u8fd9\u91cc\u6682\u65f6\u53ea\u5199\u7533\u8bf7\u4e86\u3002\u540e\u7eed\u6709\u8bf7\u5171\u540c\u4f5c\u8005\u6269\u5c55\u5185\u5bb9\u7684\u8ba1\u5212\uff0c\u5982\u613f\u610f\u8d21\u732e\u8bf7\u8054\u7cfb\u6211\u3002
"},{"location":"App/zju_ling_cs/#check-point","title":"Check Point","text":"\u5927\u4e00\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u4e13\u5fc3\u5b66\u4e13\u4e1a\u8bfe \u5927\u4e8c\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u8fdb\u7ec4\uff0c\u5b66\u4f1apytorch\uff0c\u8bad\u8fc7\u4e00\u4e9b\u5e38\u7528\u7684\u6a21\u578b \u5927\u4e09\u6691\u5047\u7ed3\u675f\u65f6\uff1a\u4ea7\u51fa\u4e00\u4f5c\u6216\u5171\u4e00\u8bba\u6587
"},{"location":"App/zju_ling_cs/#_14","title":"\u6211\u8981\u4e0d\u8981\u627e\u4e2d\u4ecb\uff1f","text":"\u4e0d\u8981\u3002 \u539f\u56e0\u4e00\uff1aCS\u7684\u5728\u7ebf\u514d\u8d39\u8d44\u6599\u8db3\u591f\u4f7f\u7528 \u539f\u56e0\u4e8c\uff1a\u4e2d\u4ecb\u7684\u4fe1\u606f\u66f4\u65b0\u901f\u5ea6\u8d76\u4e0d\u4e0aCS\u5b66\u79d1\u7684\u53d1\u5c55\u901f\u5ea6
"},{"location":"App/zju_ling_cs/#_15","title":"\u6211\u7533\u8bf7\u53ef\u4ee5\u53c2\u8003\u54ea\u4e9b\u8d44\u6599\uff1f","text":"\u7533\u8bf7MS - \u5317\u7f8e\u7684CS master Home - Open CS Application - \u9664\u5317\u7f8e\u5916\u7684\u5176\u5b83CS master Global CS (global-cs-application.github.io) - \u4e00\u4ea9\u4e09\u5206\u5730/\u5bc4\u6258\u5bb6\u56ed\u7b49\u8bba\u575b - CC98\u4e0a\u6bcf\u4e00\u5e74CS\u7684\u98de\u8dc3\u624b\u518c
\u7533\u8bf7PhD - \u6b27\u7f8eNLP\u5708\u5bf9PhD\u7533\u8bf7\u7684\u5efa\u8bae https://github.com/zhijing-jin/nlp-phd-global-equality - \u4e86\u89e3\u5b66\u79d1\u4f18\u52bf\u5b66\u6821\u548c\u5bfc\u5e08 CSRankings: Computer Science Rankings - \u6ce8\u518c\u4e00\u4e2aTwitter\u8d26\u53f7\uff0c\u5f00\u59cb\u5173\u6ce8NLP\u5708\u7684PhD\u548cAP\uff0c\u5404\u79cd\u7533\u8bf7\u673a\u4f1a\u4ed6\u4eec\u90fd\u4f1a\u5c3d\u5feb\u53d1\u5e03\u7684\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5148\u4eceAndrew Ng\u3001Christopher Manning\u3001Geoffrey Hinton\u8fd9\u79cd\u8001\u6559\u6388\u5173\u6ce8\u8d77\uff0c\u7136\u540e\u5173\u6ce8\u4ed6\u4eec\u7684\u5173\u6ce8\u8fd9\u6837\u6765\u641e\u3002 - \u5173\u6ce8\u4e00\u4ea9\u4e09\u5206\u5730/CC98/\u4e00\u4e9b\u5fae\u4fe1\u516c\u4f17\u53f7/\u77e5\u4e4e\u7684\u62db\u751f\u4fe1\u606f
"},{"location":"App/zju_ling_cs/#_16","title":"\u6295\u9012\u6691\u7814\u6ce8\u610f\u4e8b\u9879","text":"\u6d41\u7a0b\u540c\u7533\u8bf7PhD \u5df2\u7ecf\u719f\u8bc6\u7684\u5bfc\u5e08\u63a8\u8350\u662f\u6700\u5feb\u7684\uff1b\u5426\u5219\u5c31\u81ea\u5df1\u6d77\u6295\uff0c\u6295\u53d1\u5e03\u8fc7\u62db\u751f\u5e7f\u544a\u6216\u4e3b\u9875\u8868\u660e\u6b63\u5728\u62db\u751f\u7684\u8001\u5e08\u662f\u6700\u5feb\u7684\u3002\u6709\u7684\u65f6\u5019\u53ef\u4ee5\u5c1d\u8bd5\u6295\u8ba4\u8bc6\u7684PhD\uff0c\u56e0\u4e3a\u6691\u7814\u671f\u95f4\u5927\u90e8\u5206\u60c5\u51b5\u8fd8\u662f\u8ddf\u7740PhD\u6253\u5de5\u3002 \u5982\u679c\u8001\u5e08\u7ed9\u4f60\u7684\u8d23\u4efb\u6bd4\u8f83\u91cd\uff0c\u4e14\u4f60\u6709\u6bd4\u8f83\u597d\u7684\u5de5\u4f5c\u73af\u5883\uff0c\u6211\u8ba4\u4e3a\u7ebf\u4e0a\u7ebf\u4e0b\u533a\u522b\u4e0d\u5927\u3002 \u60f3\u53bb\u5317\u7f8e\u5c31\u5957\u5317\u7f8e\uff0c\u6211\u89c9\u5f97\u6700\u597d\u4e0d\u8981\u627e\u8df3\u677f\uff0c\u6709\u5317\u7f8e\u7684\u7ebf\u4e0a\u6691\u7814\u4e5f\u5f88\u597d\uff0c\u53ea\u8981\u662f\u4f60\u4e00\u4f5c\uff0c\u65f6\u957f6\u4e2a\u6708\u4ee5\u4e0a\uff0c\u6bcf\u5468\u6c47\u62a5\u8fdb\u5ea6\u3002
"},{"location":"App/zju_ling_cs/#_17","title":"\u6295\u9012\u5b9e\u4e60\u6ce8\u610f\u4e8b\u9879","text":"\u9700\u8981\u5b9e\u4e60 iff \u4f60\u6253\u7b97\u627e\u5de5or\u8bfb\u5b8c\u7855\u58eb\u627e\u5de5\uff0c\u7533\u8bf7\u5b66\u672f\u7c7bms\u548cPhD\u7684\u8bdd\uff0c\u5b9e\u4e60\u4e0d\u5f3a\u6c42\u3002
"},{"location":"App/zju_ling_cs/#-xuan-insrgithubio","title":"- \ud83c\udff3\ufe0f\u200d\ud83c\udf08 \u603b\u89c8 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io) \u627e\u6691\u671f\u5b9e\u4e60\u548c\u79cb\u62db\u7684\u7ecf\u9a8c\u5e16","text":"http://www-cc98-org-s.webvpn.zju.edu.cn:8001/topic/4950730
"},{"location":"App/zju_ling_cs/#_18","title":"\u5173\u4e8e\u7b14\u8005&\u8054\u7cfb\u7b14\u8005","text":"\u7b14\u8005\u4f30\u8ba1\u662f\u4ece\u82f1\u8bed\u4e13\u4e1a\u8f6cNLP\u89c4\u5212\u6700\u4e0d\u987a\u3001\u8fdb\u5ea6\u6700\u66f2\u6298\u7684\u4e00\u4e2a\u3002\u8fd9\u4efd\u6587\u6863\u4e0d\u662f\u4ec0\u4e48\u6210\u529f\u7ecf\u9a8c\u5206\u4eab\uff0c\u6211\u5e76\u4e0d\u6210\u529f\uff0c\u53ea\u662f\u60f3\u628a\u6211\u8e29\u8fc7\u7684\u5751\u544a\u8bc9\u540e\u4eba\uff0c\u5e0c\u671b\u5c11\u6709\u4eba\u91cd\u8e48\u6211\u7684\u8986\u8f99\u3002\u6211\u89c9\u5f97\u6211\u7684\u9ad8\u4e2d\u548c\u672c\u79d1\u8fc7\u5f97\u592a\u574e\u5777\u4e86\uff0c\u771f\u8bda\u5730\u60f3\u5e2e\u52a9\u5b66\u5f1f\u5b66\u59b9\uff0c\u5e0c\u671b\u4f60\u4eec\u4e00\u5207\u987a\u5229\u3002\u8bfb\u8005\u53ef\u4ee5\u4ee5\u6211\u4f5c\u4e3a\u57fa\u51c6\uff0c\u5728\u56db\u5e74\u540e\u4e0d\u80fd\uff08\u5f53\u7136\u5982\u679c\u65e9\u505a\u89c4\u5212\uff0c\u4e00\u76f4\u5728\u52aa\u529b\uff0c\u4e5f\u4e0d\u4f1a\uff09\u6bd4\u6211\u66f4\u5dee\u3002\u6bd5\u7adf\u4e00\u6761\u8def\u8d70\u7684\u4eba\u591a\u4e86\uff0c\u540e\u4eba\u4e00\u5b9a\u662f\u8981\u8d8a\u8d70\u8d8a\u987a\u7684\u3002
\u5982\u6709\u5efa\u8bae\u6216\u7591\u95ee\u8bf7\u901a\u8fc7\u90ae\u4ef6\u8054\u7cfb\u6211 RuoxiNing@outlook.com\u3002
"},{"location":"CS/","title":"\u7d22\u5f15","text":"\u672c\u7ae0\u8282\u5305\u62ec\u8ba1\u7b97\u673a\u79d1\u5b66\u7b14\u8bb0
"},{"location":"CS/c_lang/","title":"C\u8bed\u6cd5","text":""},{"location":"CS/c_lang/#_1","title":"\u6307\u9488","text":"\u6570\u7ec4\u540d\u662f\u4e00\u4e2a\u6307\u9488\u5e38\u91cf \u6307\u5411\u6307\u9488\u7684\u6570\u7ec4\uff08\u4e8c\u7ea7\u6307\u9488\uff09
int a = 10;\nint *p = &a;\nint **p = &p;\n
\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488
char ccolor[][] = {\"red\", \"blue\", \"yellow\"};\n
\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e00\u884c\u90fd\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u5373ccolor+i\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u7b2ci\u884c\u7684\u4e00\u7ef4\u6570\u7ec4\uff0cccolor+i\u7c7b\u578b\u662f\u201c\u957f\u5ea6\u4e3a7\u7684\u4e00\u7ef4\u6570\u7ec4\u201d\u7684\u6307\u9488\u3002ccolor[i]\u662f\u4e00\u7ef4\u6570\u7ec4
"},{"location":"CS/c_lang/#_2","title":"\u6307\u9488\u8fdb\u9636","text":"\u7c7b\u578b\u540d* \u6307\u9488\u53d8\u91cf\u540d
\u6307\u9488\u7684\u503c\u6216\u5730\u5740\u503c
double a, x[10];\ndouble *p1, *p2;\n
p1\u548cp2\u90fd\u662f\u6307\u9488\uff1ap1\u7684\u57fa\u7c7b\u578b\u662fdouble\uff0cp2\u7684\u57fa\u7c7b\u578b\u662fdouble*\uff0c\u6b64\u65f6\u90fd\u8fd8\u6ca1\u6709\u786e\u5b9a\u5730\u5740\u503c\uff0c\u9700\u8981\u8d4b\u503c\u3002
// \u8bfb\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\nchar str[100], *s;\nscanf(\"%s\", s);\n// \u8bfb\u5165\u4e00\u4e2a\u6574\u6570\nint a, *p;\nscanf(\"%d\", p);\n// \u5f15\u7528\u6307\u9488\nint c, a = 2, *p;\nc = 3 + *p;\n
\u6307\u9488\u7684\u52a0\u6cd5\u5bf9\u5730\u5740\u503c\u7684\u5f71\u54cd
\u5730\u5740\u503c\u7684\u589e\u91cf = sizeof(\u57fa\u7c7b\u578b)
\u5b9a\u4e49 \u57fa\u7c7b\u578b p\u5f53\u524d\u6307\u5411\u5730\u5740 p+1 char *p char (1 byte) 20 21 short *p short (2 bytes) 40 42 long *p long (4 bytes) 80 84\u7406\u89e3\u8fd0\u7b97\u7b26[]
a[3]\u7b49\u4ef7\u4e8e3[a]\u7b49\u4ef7\u4e8e*(3+a)
\u4e8c\u7ef4\u6570\u7ec4\u4e0e\u884c\u6307\u9488
N\u4e2a\u4eba\u56f4\u6210\u4e00\u5708\uff0c\u7b2c\u4e00\u4e2a\u4eba\u4ece1\u5f00\u59cb\u62a5\u6570\uff0c\u62a5M\u7684\u5c06\u88ab\u6740\u6389\uff0c\u4e0b\u4e00\u4e2a\u4eba\u4ece1\u5f00\u59cb\u62a5\uff0c\u6700\u540e\u5269\u4e0b\u4e00\u4e2a\uff0c\u6c42\u6700\u540e\u7684\u80dc\u5229\u8005\u3002
"},{"location":"CS/c_lang/#_4","title":"\u666e\u901a\u89e3\u6cd5","text":"\u7528\u94fe\u8868\u6a21\u62df\u8fd9\u4e2a\u8fc7\u7a0b\uff0cN\u4e2a\u4eba\u770b\u4f5cN\u4e2a\u8282\u70b9\uff0c\u8282\u70b91\u6307\u5411\u8282\u70b92\uff0c\u8282\u70b92\u6307\u5411\u8282\u70b93\uff0c\u8282\u70b9N\u6307\u5411\u8282\u70b91.
\u6bcf\u62a5\u5230M\uff0c\u5c31\u5220\u9664\u8fd9\u4e2a\u6570\u3002\u7f3a\u70b9\u662f\u8981\u6a21\u62df\u6574\u4e2a\u6e38\u620f\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u9ad8\u8fbeO(nm)\u3002
"},{"location":"CS/c_lang/#_5","title":"\u516c\u5f0f\u6cd5","text":"\u9012\u63a8\u516c\u5f0f
\\[ f(N, M) = (f(N-1, M)+M)\\%N \\]\u5176\u4e2df(M, N) \u8868\u793a N \u4e2a\u4eba\u62a5\u6570\uff0c\u6bcf\u62a5\u5230 M \u65f6\u6740\u6389\u8fd9\u4e2a\u4eba\uff0c\u6700\u540e\u80dc\u5229\u8005\u7684\u7f16\u53f7\u3002
\u600e\u6837\u63a8\u5bfc\u8be5\u516c\u5f0f\u3002
f(11, 3)
\u95ee\u98981: \u5047\u8bbe\u77e5\u905311\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4e3a6\uff0c\u4e0b\u4e00\u8f6e10\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4e3a\uff1a\u7b2c\u4e00\u8f6e\u5220\u6389\u7f16\u53f7\u4e3a3\u7684\u4eba\u540e\uff0c\u6240\u6709\u4eba\u90fd\u5f80\u524d\u79fb\u52a8\u4e863\u4f4d\uff0c\u80dc\u5229\u8005\u4e5f\u5f80\u524d\u79fb\u52a8\u4e863\u4f4d\uff0c\u6240\u4ee5\u4e0b\u6807\u75316\u53d83.
\u95ee\u98982: \u5047\u8bbe\u5df2\u77e510\u4e2a\u4eba\u65f6\uff0c\u80dc\u5229\u8005\u4e0b\u6807\u4e3a3\uff0c\u90a3\u4e0b\u4e00\u8f6e11\u4e2a\u4eba\u65f6\u80dc\u5229\u8005\u7684\u4e0b\u6807\u662f\uff1f
\u53ef\u4ee5\u770b\u4f5c\u4e0a\u4e2a\u8fc7\u7a0b\u7684\u9006\u8fc7\u7a0b\uff0c\u5927\u5bb6\u90fd\u5f80\u540e\u79fb\u52a83\u4f4d\uff0c\u6240\u4ee5f(11, 3) = f(10, 3) + 3\u3002\u4e0d\u8fc7\u6709\u53ef\u80fd\u6570\u7ec4\u4f1a\u8d8a\u754c\uff0c\u6240\u4ee5\u6700\u540e\u6a21\u5f53\u524d\u4eba\u6570\u7684\u4e2a\u6570\uff0cf(11, 3) = (f(10, 3) + 3) %11
\u95ee\u98983: \u73b0\u5728\u6539\u6210\u4eba\u6570\u4e3aN\uff0c\u62a5\u5230M\u65f6\u628a\u4eba\u6740\u6389\uff0c\u6570\u7ec4\u662f\u600e\u6837\u79fb\u52a8\u7684\uff1f\u6bcf\u6740\u6389\u4e00\u4e2a\u4eba\uff0c\u4e0b\u4e00\u4e2a\u4eba\u6210\u4e3a\u5934\uff0c\u76f8\u5f53\u4e8e\u628a\u6570\u7ec4\u5411\u524d\u79fb\u52a8M\u4f4d\u3002\u82e5\u5df2\u77e5N-1\u4e2a\u4eba\u65f6\uff0c\u80dc\u5229\u8005\u7684\u4e0b\u6807\u4f4d\u7f6ef(N-1, M)\uff0c\u5219N\u4e2a\u4eba\u65f6\uff0c\u5c31\u662f\u5f80\u540e\u79fb\u52a8M\uff0c\u8003\u8651\u5230\u6570\u7ec4\u8d8a\u754c\uff0c\u8981\u6a21N\uff0c\u5373f(N, M) = (f(N-1, M) + M) % N\u3002
int cir(int n, int m)\n{\nint p = 0;\nfor (int i=2; i<=n; i++)\n{\np=(p+m)%i;\n}\nreturn p+1;\n}\n
"},{"location":"CS/coding_code/","title":"\u7f16\u7a0b\u89c4\u8303\u6587\u6863\u6a21\u677f","text":"\u4e00\u4efd\u7528\u4e8eC\u5927\u7a0b\u7684\u7b80\u6613\u7f16\u7a0b\u89c4\u8303\u6587\u6863\u3002 \u4e3a\u7edf\u4e00\u5c0f\u7ec4\u6210\u5458\u5728\u8f6f\u4ef6\u5f00\u53d1\u8bbe\u8ba1\u8fc7\u7a0b\u4e2d\u7684\u4ee3\u7801\u98ce\u683c\uff0c\u65b9\u4fbf\u7ec4\u5458\u4e92\u76f8\u4e4b\u95f4\u534f\u4f5c\uff0c\u7279\u63d0\u51fa\u4ee5\u4e0b\u7f16\u7801\u89c4\u8303\u3002
"},{"location":"CS/coding_code/#_1","title":"\u6392\u7248\u89c4\u8303","text":"\u7f16\u7801\u89c4\u8303\u8bf4\u660e\u6587\u6863_\u7f16\u7801\u89c4\u8303\u6587\u6863_\u67ef\u897f\u6ca1\u79d1\u6c14\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/crawler/","title":"\u5199\u4e2a\u722c\u866bCrawler\ud83d\udd77\ufe0f\uff01","text":"\u89e3\u6790html\u7684\u6b65\u9aa4\uff1a - \u5c42\u6b21\u5316\u7684\u6570\u636e - \u6709\u591a\u4e2a\u89e3\u6790html\u7684\u4e09\u65b9\u5e93\uff0c\u5982\uff1alxml\uff0cbeautifulsoup\uff0chtmlparser
"},{"location":"CS/crawler/#requests","title":"requests","text":"import requests\n
\u53cd\u53cd\u722c\u7684
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\n
"},{"location":"CS/crawler/#beautifulsoup","title":"Beautifulsoup","text":""},{"location":"CS/crawler/#_1","title":"\u5b89\u88c5\u548c\u521d\u59cb\u5316","text":"pip install beautifulsoup4\n
\u89e3\u6790\u7684\u7b2c\u4e00\u6b65\u662f\u6784\u5efa\u4e00\u4e2abeautifulsoup\u5bf9\u8c61
from bs4 import BeautifulSoup\nsoup = BeautifulSoup(html_doc, 'html_parser')\n
"},{"location":"CS/crawler/#_2","title":"\u4ecb\u7ecd","text":"\u7b2c\u4e00\u4e2a\u53c2\u6570html_doc\u662f\u8bfb\u53d6\u7684html\u6587\u6863\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u89e3\u6790\u5668\uff0cbeautifulsoup\u652f\u6301\u4ee5\u4e0b\u89e3\u6790\u5668
\u89e3\u6790\u5668 \u4f7f\u7528\u65b9\u6cd5 \u4f18\u52bf \u52a3\u52bf Python\u6807\u51c6\u5e93 BeautifulSoup(markup, \u201chtml.parser\u201d) \u4e2d\u6587\u4e0d\u884c lxml HTML\u89e3\u6790\u5668 BeautifulSoup(markup, \u201clxml\u201d) \u5feb C\u8bed\u8a00\u5e93 lxml XML\u89e3\u6790\u5668 BeautifulSoup(markup, [\u201dlxml-xml\u201d]), BeautifulSoup(markup, \u201cxml\u201d) \u5feb C\u8bed\u8a00\u5e93 htmlSlib BeautifulSoup(markup, \u201chtml5lib\u201d) \u51c6 \u6162BeautifulSoup\u7c7b\u7684\u57fa\u672c\u5143\u7d20
\u57fa\u672c\u5143\u7d20 \u8bf4\u660e Tag \u6807\u7b7e\uff0c\u6700\u57fa\u672c\u7684\u4fe1\u606f\u7ec4\u7ec7\u5355\u5143\uff0c\u5206\u522b\u7528<>\u548c\u6807\u660e\u5f00\u5934\u548c\u7ed3\u5c3e Name \u6807\u7b7e\u7684\u540d\u5b57\uff0c\u5373\u5c16\u62ec\u53f7\u91cc\u7684\u5185\u5bb9 Attribute \u6807\u7b7e\u7684\u5c5e\u6027\uff0c\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178 NavigableString \u6807\u7b7e\u5185\u7684\u975e\u5c5e\u6027\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e00\u4e2aString Comment \u6807\u7b7e\u5185\u5b57\u7b26\u4e32\u7684\u6ce8\u91ca\u90e8\u5206\uff0c\u4e00\u79cd\u7279\u6b8a\u7684Comment\u7c7b\u578b"},{"location":"CS/crawler/#_3","title":"\u4f7f\u7528\u65b9\u6cd5","text":"\u8bbf\u95ee\u6807\u7b7e\uff1a\u7528soup.\u7684\u683c\u5f0f\uff0c\u6bcf\u6b21\u53ea\u80fd\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5339\u914d\u7684tag\u3002
soup = BeautifulSoup(html_doc, 'lxml')\nprint(soup.head) #<head><title>The Dormouse's story</title><head>\nprint(soup.head.title) # <title>The Dormouse's story</title>\nprint(soup.a) # <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\n
\u8bbf\u95ee\u591a\u4e2a\u6807\u7b7e\uff1b\u4f7f\u7528soup.find_all(\u2019\u2019)\u3002\u4f1a\u8fd4\u56de\u4e00\u4e2alist.
soup.find_all('a')\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>, <a class=\"sister\" href=\"http://example.com/lacie\" id=\"link2\">Lacie</a>, <a class=\"sister\" href=\"http://example.com/tillie\" id=\"link3\">Tillie</a>]\nsoup.find_all('a')[0]\n// <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\n
\u53ef\u4ee5\u5728find_all\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u8fc7\u6ee4\u6761\u4ef6\u3002
soup.find_all('a', text = 'Elsie')\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>]\nsoup.find_all('a', attrs = {'id': 'link1'})\n// [<a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>]\nsoup.find_all('a', id = 'link1')\n// \u4f46\u662f\u8fd9\u6837\u5199\u4e0d\u9002\u7528\u4e8e\u6240\u6709\u5c5e\u6027\uff1f\nsoup.find_all('p', class_= 'title')\n// [<p class=\"title\"><b>The Dormouse's story</b></p>]\n// \u8fd9\u79cd\u662fCSS\u9009\u62e9\u5668\n
"},{"location":"CS/crawler/#_4","title":"\u8bbf\u95ee\u6807\u7b7e\u5185\u5bb9\u548c\u5c5e\u6027","text":"\u901a\u8fc7 name \u548c string \u53ef\u4ee5\u8bbf\u95ee\u6807\u7b7e\u7684\u540d\u5b57\u548c\u5185\u5bb9\uff0c\u901a\u8fc7 get \u548c\u4e2d\u62ec\u53f7\u64cd\u4f5c\u7b26\u53ef\u4ee5\u8bbf\u95ee\u6807\u7b7e\u4e2d\u7684\u5c5e\u6027\u548c\u503c\u3002
print(soup.a)\n## <a class=\"sister\" href=\"http://example.com/elsie\" id=\"link1\">Elsie</a>\nprint(soup.a['class'])\n## ['sister']\nprint(soup.a.get('class'))\n## ['sister']\nprint(soup.a.name)\n## 'a'\nprint(soup.a.string)\n## 'Elsie'\n
"},{"location":"CS/crawler/#_5","title":"\u89e3\u6790\u7f51\u9875","text":"import requests\nimport chardet\nfrom bs4 import BeautifulSoup\nheaders = {\n'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\nurl = \"\"\nrqg = requests.get(url, headers = hearders, timeout = 3.0)\nrqg.encoding = chardet.detect(rqg.content)['encoding'] # requests \u8bf7\u6c42\u8fc7\u7a0b\n# \u521d\u59cb\u5316HTML\nhtml = rqg.content.decode('utf-8')\nsoup = BeautifulSoup(html, 'lxml') # \u751f\u6210 BeautifulSoup \u5bf9\u8c61\nprint('\u8f93\u51fa\u683c\u5f0f\u5316\u7684BeautifulSoup\u5bf9\u8c61\uff1a', soup.prettify())\nprint('\u540d\u4e3atitle\u7684\u5168\u90e8\u5b57\u8282\u70b9\uff1a', soup.find_all(\"title\"))\nprint('title\u5b50\u8282\u70b9\u7684\u6587\u672c\u5185\u5bb9:', soup.title.string)\nprint('\u4f7f\u7528get_text()\u83b7\u53d6\u7684\u6587\u672c\u5185\u5bb9\uff1a', soup.title.get())\ntarget = soup.find_all('ul', class_ = 'menu') # \u6309\u7167CSS\u7c7b\u540d\u5b8c\u5168\u5339\u914d\ntarget = soup.find_all(id = 'menu') # \u4f20\u5165\u5173\u952e\u5b57id\uff0c\u641c\u7d22\u7b26\u5408\u6761\u4ef6\u7684\u8282\u70b9\ntarget = soup.ul.find_all('a') # \u6240\u6709\u540d\u79f0\u4e3aa\u7684\u8282\u70b9\n
"},{"location":"CS/crawler/#lxmlxpath","title":"lxml\u7684XPath","text":"lxml\u8fd9\u4e2a\u5e93\u540c\u65f6\u652f\u6301HTML\u548cXML\u7684\u89e3\u6790\uff0c\u652f\u6301XPath\u89e3\u6790\u65b9\u5f0f\uff0c\u89e3\u6790\u6548\u7387\u9ad8\u3002
\u4f7f\u7528xpath\u9700\u8981\u4ecelxml\u5e93\u4e2d\u5012\u5165etree\u6a21\u5757\uff0c\u9700\u8981\u4f7f\u7528html\u7c7b\u5bf9\u9700\u8981\u5339\u914d\u7684html\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\u3002
import requests\nimport chardet\nfrom lxml import etree\nheaders = {\n'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}\nurl = \"\"\nrqg = requests.get(url, headers = hearders, timeout = 3.0)\nrqg.encoding = chardet.detect(rqg.content)['encoding'] # requests \u8bf7\u6c42\u8fc7\u7a0b\n# \u521d\u59cb\u5316HTML\nhtml = rqg.content.decode('utf-8')\nhtml = etree.HTML(html, parser = etree.HTMLParser(encoding = 'utf-8'))\n
\u5b89\u88c5\u9014\u5f84
pip install lxml\n
Xpath\u5e38\u7528\u7684\u8868\u8fbe\u5f0f
\u8868\u8fbe\u5f0f \u63cf\u8ff0 nodename \u9009\u53d6\u6b64\u8282\u70b9\u7684\u6240\u6709\u5b50\u8282\u70b9\u3002 / \u4ece\u6839\u8282\u70b9\u9009\u53d6\u3002 // \u4ece\u5339\u914d\u9009\u62e9\u7684\u5f53\u524d\u8282\u70b9\u9009\u62e9\u6587\u6863\u4e2d\u7684\u8282\u70b9 . \u9009\u53d6\u5f53\u524d\u8282\u70b9\u3002 \u2026 \u9009\u53d6\u5f53\u524d\u8282\u70b9\u7684\u7236\u8282\u70b9\u3002 @ \u9009\u53d6\u5c5e\u6027\u3002\u4f7f\u7528\u8868\u8fbe\u5f0f\u5b9a\u4f4dhead\u548ctitle\u8282\u70b9
result = html.xpath('head') ## \u901a\u8fc7\u540d\u79f0\u5b9a\u4e3ahead\u8282\u70b9\nresult1 = html.xpath('/html/heda/title') ## \u6309\u8282\u70b9\u5c42\u7ea7\u5b9a\u4f4dtitle\u8282\u70b9\nresult2 = html.xpath('//title') ## \u4e5f\u53ef\u4ee5\u5b9a\u4f4dtitle\u8282\u70b9\n
Xpath\u8c13\u8bcd\u5e38\u7528\u7684\u8868\u8fbe\u5f0f
\u8868\u8fbe\u5f0f \u7ed3\u679c xpath(\u2019/body/div[1]\u2019) \u9009\u53d6body\u4e0b\u7684\u7b2c\u4e00\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[last()]\u2019) \u9009\u53d6body\u4e0b\u6700\u540e\u4e00\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[last()-1]\u2019) \u9009\u53d6body\u4e0b\u5012\u6570\u7b2c\u4e8c\u4e2adiv\u8282\u70b9 xpath(\u2019/body/div[position()<3]\u2019) \u9009\u53d6body\u4e0b\u524d\u4e24\u4e2a\u8282\u70b9 xpath(\u2019/body/div[@class]\u2019) \u9009\u53d6body\u4e0b\u5e26\u6709class\u5c5e\u6027\u7684div\u8282\u70b9 xpath(/body/div[@class=\u201dmain\u201d]\u2019) \u9009\u53d6body\u4e0bclass\u5c5e\u6027\u4e3amain\u7684div\u8282\u70b9 xpath(\u201d/body/div[price>35]\u201d) \u9009\u53d6body\u4e0bprice\u5143\u7d20\u503c\u5927\u4e8e35\u7684\u8282\u70b9"},{"location":"CS/crawler/#request-html","title":"request-html","text":"requests-html\u7406\u89e3\u4e3a\u53ef\u4ee5\u89e3\u6790HTML\u6587\u6863\u7684request\u5e93
pip install requests-html\n
\u83b7\u53d6\u4e00\u4e2auser-agent
user_agent = requests_html.user_agent()\n
\u5bf9JavaScript\u7684\u652f\u6301\u662frequests-html\u6700\u5927\u7684\u4eae\u70b9\uff0c\u4f1a\u7528\u5230render\u51fd\u6570\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5b83\u4f1a\u5148\u4e0b\u8f7dChromium\uff0c\u7136\u540e\u4f7f\u7528Chromium\u6765\u6267\u884c\u4ee3\u7801\uff0c\u4f46\u662f\u4e0b\u8f7d\u7684\u65f6\u5019\u53ef\u80fd\u9700\u8981\u4e00\u4e2a\u68af\u5b50\u3002
\u793a\u4f8b
from requests_html import HTMLSession\nsession = HTMLSession()\ndef parse():\nr = session.get('http://www.qdaily.com/')\n# \u83b7\u53d6\u9996\u9875\u65b0\u95fb\u6807\u7b7e\u3001\u56fe\u7247\u3001\u6807\u9898\u3001\u53d1\u5e03\u65f6\u95f4\nfor x in r.html.find('.packery-item'):\nyield {\n'tag': x.find('.category')[0].text,\n'image': x.find('.lazyload')[0].attrs['data-src'],\n'title': x.find('.smart-dotdotdot')[0].text if x.find('.smart-dotdotdot') else x.find('.smart-lines')[0].text,\n'addtime': x.find('.smart-date')[0].attrs['data-origindate'][:-6]\n}\n
\u901a\u8fc7\u7b80\u77ed\u7684\u51e0\u884c\u4ee3\u7801\uff0c\u5c31\u53ef\u4ee5\u628a\u6574\u4e2a\u9996\u9875\u7684\u6587\u7ae0\u6293\u53d6\u4e0b\u6765\u3002
\u793a\u4f8b\u4e2d\u4f7f\u7528\u7684\u51e0\u4e2a\u65b9\u6cd5\uff1a
\u2460 find( ) \u53ef\u4ee5\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff1a
\u7b2c\u4e00\u4e2a\u53c2\u6570\u53ef\u4ee5\u662fclass\u540d\u79f0\u6216ID\u7b2c\u4e8c\u4e2a\u53c2\u6570first=True\u65f6\uff0c\u53ea\u9009\u53d6\u7b2c\u4e00\u6761\u6570\u636e
\u2461 text \u83b7\u53d6\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9
\u2462 attrs \u83b7\u53d6\u5143\u7d20\u7684\u5c5e\u6027\uff0c\u8fd4\u56de\u503c\u662f\u4e2a\u5b57\u5178
\u2463 html \u83b7\u53d6\u5143\u7d20\u7684html\u5185\u5bb9
\u4f7f\u7528requests-html\u6765\u89e3\u6790\u5185\u5bb9\u7684\u597d\u5904\u5728\u4e8e\u4f5c\u8005\u90fd\u9ad8\u5ea6\u5c01\u88c5\u8fc7\u4e86\uff0c\u8fde\u8bf7\u6c42\u8fd4\u56de\u5185\u5bb9\u7684\u7f16\u7801\u683c\u5f0f\u8f6c\u6362\u4e5f\u81ea\u52a8\u505a\u4e86\uff0c\u5b8c\u5168\u53ef\u4ee5\u8ba9\u4ee3\u7801\u903b\u8f91\u66f4\u7b80\u5355\u76f4\u63a5\uff0c\u66f4\u4e13\u6ce8\u4e8e\u89e3\u6790\u5de5\u4f5c\u672c\u8eab\u3002
"},{"location":"CS/libgraphics/","title":"C\u5927\u7a0b libgraphics \u6587\u6863 \u4f7f\u7528\u8bb0\u5f55","text":"\u26a0\ufe0f \u6ca1\u5199\u5b8c TODO
"},{"location":"CS/libgraphics/#_1","title":"\u5df2\u77e5\u95ee\u9898","text":"\u2192\u4fee\u6539Makefile.win\uff0c\u5728\u672b\u5c3e\u52a0\u5165\uff08\u81ea\u5df1\u5b9e\u8df5\u7684\u65f6\u5019\u8fd9\u6b65\u4e0d\u52a0\u597d\u50cf\u4e5f\u884c\uff09
gratest1.o:gratest1.c\n$(CC) -c gratest1.c -o gratest1.o $(CFLAGS)\n
graphics.h \u4ec5\u63d0\u4f9b\u4ee5\u4e0b\u5c11\u91cf\u753b\u56fe\u51fd\u6570\u63a5\u53e3
InitGraphics();\nMovePen(x, y);\nDrawLine(dx, dy);\nDrawArc(r, start, sweep);\nGetWindowWidth();\nGetWindowHeight();\nGetCurrentX();\nGetCurrentY();\n
\u6211\u4eec\u5c06\u5728\u4e0b\u9762\u4ecb\u7ecd\u8fd9\u4e9b\u63a5\u53e3\u7684\u7528\u6cd5\u3002
"},{"location":"CS/libgraphics/#_3","title":"\u521d\u59cb\u5316\u64cd\u4f5c","text":"\u5728main.c\u91cc\u9700\u8981\u8fdb\u884c\u5982\u4e0b\u521d\u59cb\u5316
#include \"graphics.h\"\n#include \"extragraph.h\"\n#include \"imgui.h\"\nvoid Main() // \u6ce8\u610f\u8fd9\u91cc\u9700\u8981\u4f7f\u7528\u5927\u5199Main\n{\nSet WindowTitle(\"Your Title\");\nInitGraphics(); // \u8c03\u7528\u4e86\u56fe\u5f62\u6a21\u5f0f\n}\n
InitGraphics(); \u8fd9\u4e2a\u51fd\u6570\u4f1a\u6253\u5f00\u4e00\u4e2a\u7a7a\u7684\u56fe\u5f62\u7a97\u53e3\u3002
"},{"location":"CS/libgraphics/#_4","title":"\u7a97\u53e3","text":"\u4ee5\u4e0b\u56db\u4e2a\u51fd\u6570\u90fd\u4e0d\u9700\u8981\u4f20\u5165\u53c2\u6570\uff0c\u5206\u522b\u8fd4\u56de\u7a97\u53e3\u5bbd\u3001\u9ad8\uff0c\u5f53\u524dX\u3001Y\u5750\u6807\u3002
GetWindowWidth();\nGetWindowHeight();\nGetCurrentX();\nGetCurrentY();\n
"},{"location":"CS/libgraphics/#_5","title":"\u597d\u7684\u7f16\u5199\u4e60\u60ef","text":"\u5e94\u8be5\u5148\u5b9a\u4e49\u4e00\u4e9b\u5e38\u91cf\uff0c\u7ed9\u8fd9\u4e9b\u5e38\u91cf\u53d6\u540d\u5b57
#define HouseHeight 2.0\n#define HouseWidth 3.0\n#define AtticHeight 0.7\n#define DoorWidth 0.4\n#define DoorKnobRadius 0.03\n#define DoorKnobInset 0.07\n#define PaneHeight 0.25\n#define PaneWidth 0.2\n#define FirstFloorWindows 0.3\n#define SecondFloorWindows 1.25\n
"},{"location":"CS/libgraphics/#_6","title":"\u753b\u56fe\u5f62\u7684","text":""},{"location":"CS/libgraphics/#movepen","title":"MovePen","text":"\u5c06\u7b14\u79fb\u52a8\u5230(x, y)\u8be5\u5750\u6807\u3002\u6ce8\u610f\u5f53\u753b\u56fe\u5f62\u65f6\uff0c\u540e\u9762\u51e0\u4e2a\u51fd\u6570\u7684\u76f8\u5bf9\u4f4d\u79fb\uff0c\u90fd\u662f\u76f8\u5bf9\u4e8e\u8fd9\u4e2a\u51fd\u6570\u8bbe\u7f6e\u7684\u7b14\u5750\u6807\u79fb\u52a8\u7684\u3002
MovePen(double x, double y);\n
"},{"location":"CS/libgraphics/#drawline","title":"DrawLine","text":"\u5728\u753b\u7ebf\u4e4b\u524d\u4e00\u5b9a\u8981MovePen();
DrawLine(double dx, double dy);\n
\u753b\u7ebf\u7684\u65b9\u5411\uff1a
\u6a2a\u5750\u6807\u6700\u5de6\u8fb9\u662f0\uff0c\u5411\u53f3\u589e\u5927
\u7eb5\u5750\u6807\u6700\u4e0b\u9762\u662f0\uff0c\u5411\u4e0a\u589e\u5927
\u53ef\u4ee5\u7406\u89e3\u4e3a\u6211\u4eec\u5728\u7b2c\u4e00\u8c61\u9650
"},{"location":"CS/libgraphics/#drawarc","title":"DrawArc","text":"\u5728\u753b\u5f27\u4e4b\u524d\u4e00\u5b9a\u8981MovePen();
DrawArc(double r, double start, double sweep);\n
"},{"location":"CS/libgraphics/#_7","title":"\u6211\u4eec\u5e94\u5f53\u628a\u753b\u77e9\u5f62\u5c01\u88c5\u6210\u4e00\u4e2a\u65b0\u7684\u51fd\u6570","text":"void DrawBox (double x, double y, double width, double height)\n{\nMovePen(x, y);\nDrawLine(0, height);\nDrawLine(width, 0);\nDrawLine(0, height);\nDrawLine(-width, 0);\n}\n
void DrawCenteredBox(double x, double y, double width, double height)\n{\nDrawBox(w - width/2, y - height/2, width, height);\n}\n
"},{"location":"CS/libgraphics/#_8","title":"\u753b\u5706\u7684\u51fd\u6570","text":"void DrawCenteredCircle(double x, double y, double r)\n{\nMovePen(x + r, y);\nDrawArc(r, 0, 360);\n}\n
"},{"location":"CS/libgraphics/#_9","title":"\u6587\u5b57","text":"\u4ece\u5f53\u524d\u4f4d\u7f6e\u5f00\u59cb\u8f93\u51fa\u6587\u672c\u4e32
DrawTextString(string);\n
\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u67d0\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6
double stringLen = TextStringWidth(string);
"},{"location":"CS/libgraphics/#_10","title":"\u67e5\u770b\u56de\u8c03\u51fd\u6570\u7c7b\u578b","text":"typedef void(* KeyboardEventCallback)(int key, int event);\n
"},{"location":"CS/libgraphics/#_11","title":"\u5b9a\u65f6\u5668","text":""},{"location":"CS/libgraphics/#_12","title":"\u65f6\u95f4\u56de\u8c03\u51fd\u6570","text":"registerTimerEvent(mytimer); //\u83b7\u53d6\u7535\u8111\u65f6\u949f\u4fe1\u606f\u8fd4\u56de\u7ed9mytimer\nstartTimer(0, (int)(1000/speed)); // \u8981\u8ba8\u8bba\u4f20\u8fdb\u6765\u7684timer\u662f\u4ec0\u4e48\n
"},{"location":"CS/libgraphics/#_13","title":"\u5b9a\u65f6\u5668\u6d88\u606f\u56de\u8c03\u51fd\u6570","text":"void TimerEventProcess(int timerID);\n
\u793a\u4f8b
typedef enum\n{\nLabelTimer,\nBoxTimer,\n} MyTimer;\n
void mytimer(int timerID)\n{\nswitch (timerID)\n{\ncase LabelTimer:\nlabel_x += 0.5;\nif (label_x > 5.0) label_x = 1.0;\ndisplay();\nbreak;\ncase BoxTimer:\nbox_y += 0.5;\nif (box_y > 5.0) box_y = 1.0;\ndisplay();\nbreak;\nbreak;\n}\n}\n
registerTimerEvent(mytimer);\nstartTimer(LabelTimer, 100);\nstartTimer(BoxTimer, 200);\n
"},{"location":"CS/libgraphics/#_14","title":"\u9f20\u6807","text":""},{"location":"CS/libgraphics/#_15","title":"\u9f20\u6807\u6d88\u606f\u56de\u8c03\u51fd\u6570","text":"void MouseEventProcess(int x, int y, int button, int event);\n
x, y - \u4f4d\u7f6e\u5750\u6807
button - \u6309\u4e0b\u7684\u662f\u54ea\u4e2a\u952e
event - \u6309\u4e0b\uff0c\u677e\u5f00\uff0c\u79fb\u52a8\u7b49\u4e8b\u4ef6
void myMouseEvent (int x, int y, int button, int event)\n{\nmouse_x = ScaleXInches(x); // \u8fd9\u4e2a\u51fd\u6570\u5728extragraph\u5e93\u91cc\nmouse_y = ScaleYInches(y);\ndisplay();\n}\n
\u9700\u8981\u5728Main()\u91cc\u6dfb\u52a0\u8fd9\u4e00\u884c
registerMouseEvent(myMouseEvent);\n
\u5728display()\u91cc
void display()\n{\ndouble w = 1.0;\ndouble h = GetFontHeight() * 2;\n// \u6e05\u9664\u5c4f\u5e55\nDisplayClear();\n// draw a square\nSetPenColor(\"Red\");\ndrawLabel(label_x, label_y, \"Lable is Here\");\n//draw a rect/box to trace the mouse\n//drawRectangle(mouse_x, mouse_y, w, h, 0);\nSetPenColor(\"Blue\");\ndrawBox(mouse_x, mouse_y, w, h, 1, \"This box follows the mouse\", 'L', \"Red\");\n}\n
"},{"location":"CS/libgraphics/#linkedlist","title":"\u4f7f\u7528linkedlist\u5e93","text":"#include \"linkedlist.h\"\n
\u521b\u5efa\u4e00\u4e2a linkedlist \u540d\u53eb g_polylines
linkedlistADT g_polylines = NULL;\ng_polylines = NewLinkedList();\ndisplay();\n
void display()\n{\nlinkedlistADT poly = NextNode(g_polylines, g_polylines);\nSetPenColor(\"Blue\");\nif (poly) {\nPoint * p = (Point*) NodeObj(g_polylines, poly);\ndouble lx = p->x;\ndouble ly = p->y;\nMovePen(lx, ly);\nwhile (poly = NextNode(g_polylines, poly))\n{\np = (Point*) NodeObj(g_polylines, poly);\nDrawLine(p->x - lx, p->y - ly);\nlx = p->x;\nly = p->y;\n}\n}\n}\n
"},{"location":"CS/libgraphics/#button","title":"\u4f7f\u7528button\u548c\u952e\u76d8","text":"\u8fd9\u6b21\u9700\u8981\u7528\u5230\u7684\u5e93
#include <windows.h>\n#include <winuser.h>\n#include \"graphics.h\"\n#include \"extgraph.h\"\n#include \"imgui.h\"\n#include \"linkedlist.h\"\n
"},{"location":"CS/libgraphics/#_16","title":"\u5b57\u7b26\u8f93\u5165\u56de\u8c03\u51fd\u6570","text":"void charEventProcess(char c);\n
c - \u8f93\u5165\u5b57\u7b26\u7684ASCII\u7801
"},{"location":"CS/libgraphics/#_17","title":"\u952e\u76d8\u56de\u8c03\u51fd\u6570","text":"void KeyboardEventProcess(int key, int event);\n
key - \u54ea\u4e2a\u952e
event - \u6309\u4e0b\u8fd8\u662f\u677e\u5f00
\u793a\u4f8b
\u5728Main()\u4e2d
\n
void myKeyboardEvent(int key, int event)\n{\nuiGetKeyboard(key, event); // needed for using simpleGUI\ndisplay();\nswitch (event)\n{\ncase KEY_UP:\nif (key == VK_F1)\ng_add_point = !g_add_point;\nbreak;\ndefault:\nbreak;\n}\n}\n
"},{"location":"CS/libgraphics/#_18","title":"\u989c\u8272\u5e93","text":"\u81ea\u5e26\u7684\u989c\u8272\u5217\u8868
char colorlist[100][100] = {\u201dBlack\u201d, \u201cDark Gray\u201d, \u201cGray\u201d, \u201cLight Gary\u201d, \u201cWhite\u201d, \u201cBrown\u201d, \u201cRed\u201d, \u201cOrange\u201d, \u201cYellow\u201d, \u201cGreen\u201d, \u201cBlue\u201d, \u201cViolet\u201d, \u201cMagenta\u201d, \u201cCyan\u201d};\nconst int colorNumber = 14;\n
\u81ea\u5b9a\u4e49\u989c\u8272
\u989c\u8272\u4f1a\u88ab\u52a0\u5165\u989c\u8272\u5e93\uff0cRGB\u7684\u53d6\u503c\u8303\u56f4\u90fd\u662f[0, 1]\u800c\u4e0d\u662f[0, 256)
DefineColor(\"Color Name\", R, G, B);\n
"},{"location":"CS/libgraphics/#libgraphics","title":"libgraphics\u5176\u5b83\u5e38\u7528\u7684\u4e1c\u897f","text":""},{"location":"CS/objdump/","title":"Objdump\u5de5\u5177","text":"\u6e90\u4ee3\u7801\u6587\u4ef6\u540dmytest.c
gcc -c -g -o mytest mytest.c\nobjdump -s -d main.o > main.o.txt\n
\u76ee\u6807\u6587\u4ef6\u53cd\u6c47\u7f16\uff0c\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -c -o main.o main.c\nobjdump -S -d main.o > main.o.txt\n
\u663e\u793a\u6e90\u4ee3\u7801\u7684\u540c\u65f6\u663e\u793a\u884c\u53f7
objdump -j .text -ld -C -S main.o > main.o.txt\n
\u53ef\u6267\u884c\u6587\u4ef6\u53cd\u6c47\u7f16
gcc -o main main.c\nobjdump -s -d main > main.txt\n
\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -o main main.c\nobjdump -S -d main > main.txt\n
"},{"location":"CS/x86assm/","title":"x86\u6c47\u7f16","text":""},{"location":"CS/x86assm/#lab","title":"Lab\u8bb0\u5f55","text":"\u26a0 Lab\u5df2\u7ecf\u5168\u90e8\u6362\u6389\uff0c\u8fd9\u90e8\u5206\u4f5c\u4e1a\u4ecb\u7ecd\u65e0\u6cd5\u53c2\u8003\u4e86\u3002 1. \u4f5c\u4e1a1: \u5b57\u7b26\u4e32\u8f6c\u6362 \u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5c0f\u5199\u5b57\u6bcd\u5168\u90e8\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\uff0c\u5220\u9664\u7a7a\u683c\u540e\u8f93\u51fa\u3002 \u8bb0\u5f97\u4ed6\u6709\u5b57\u7b26\u4e32\u8bfb\u5199\u7684\u6e90\u4ee3\u7801\u3002 2. \u4f5c\u4e1a2: \u6253\u5370ASCII\u7801\u8868 \u8fdb\u5165\u56fe\u5f62\u6a21\u5f0f\uff0c\u8f93\u51fa\u7ea2\u7684ascii\u7801\u548c\u7eff\u7684\u76f8\u5e94\u5341\u516d\u8fdb\u5236\u7f16\u53f7\u3002 \u4e2a\u4eba\u611f\u89c9\u5148\u628a\u4f4d\u79fb\u5199\u51fa\u6765\u518d\u586b\u91cc\u9762\u7684\u8f93\u51fa\u6bd4\u8f83\u597d\u5f04\u3002 \u53ef\u4ee5\u53c2\u7167\u4ed6\u7684\u6570\u5b57\u7528\u5faa\u73af\u5de6\u79fb\u8f93\u51fa\u6210\u5341\u516d\u8fdb\u5236\u4ee3\u7801\u3002 3. \u4f5c\u4e1a3: \u7b80\u6613\u8ba1\u7b97\u5668 \u6574\u4f53\u601d\u8def\uff1a80386\u8bed\u6cd5\u5199\uff0c\u5185\u5bb9\u90fd\u5b58\u5728\u5185\u5b58\u53d8\u91cf\u91cc \u52a0\u6cd5\u601d\u8def\uff1a\u9ad8\u4f4d\u52a0\u9ad8\u4f4d\uff0c\u4f4e\u4f4d\u52a0\u4f4e\u4f4d \u4e58\u6cd5\u601d\u8def\uff1a\u5206\u522b\u4e58\u4f4e\u4f4d\u548c\u9ad8\u4f4d\uff0c\u9ad8\u4f4d\u7ed3\u679c\u52a0\u8fdb\u4f4d \u9664\u6cd5\u601d\u8def\uff1a\u5206\u522b\u9664\u9ad8\u4f4d\u548c\u4f4e\u4f4d\uff0c\u3002\u3002\u540e\u9762\u5fd8\u4e86 \u8f93\u51fa\u5341\u8fdb\u5236\u601d\u8def\uff1a\u9ad8\u4f4d\u4f4e\u4f4d \u8f93\u51fa\u5341\u516d\u8fdb\u5236\u601d\u8def\uff1a 4. \u4f5c\u4e1a4: C\u4ee3\u7801\u6587\u4ef6\u67e5\u770b\u5668\u7ffb\u8bd1\u6210\u6c47\u7f16 \u4ed6\u4f1a\u7ed9\u4e00\u4e2ac\u6e90\u4ee3\u7801\uff0c\u7528c\u548c\u6c47\u7f16\u5939\u5fc3\u8c03\u8bd5\u628ac\u7ffb\u8bd1\u6210\u6c47\u7f16\u3002 \u903b\u8f91\u7684\u601d\u8def\uff1a \u5bc4\u5b58\u5668\u72b6\u6001\u4fdd\u5b58+\u521d\u59cb\u72b6\u6001+\u5224\u65ad\u7ec8\u6b62+\u64cd\u4f5c+\u50a8\u5b58+\u5faa\u73af\u6761\u4ef6+\u8df3\u8f6c+\u5bc4\u5b58\u5668\u72b6\u6001\u6062\u590d
"},{"location":"CS/x86assm/#6","title":"6\u79cd\u5bfb\u5740\u65b9\u5f0f\u4e0e\u5176\u4f5c\u7528","text":"\u8bf4\u660e \u793a\u4f8b \u4f5c\u7528 \u7acb\u5373\u5bfb\u5740 mov eax,56H \u901a\u5e38\u7528\u4e8e\u8d4b\u503c \u76f4\u63a5\u5bfb\u5740 mov eax,[1255887H] \u901a\u5e38\u7528\u4e8e\u5904\u7406\u53d8\u91cf \u5bc4\u5b58\u5668\u5bfb\u5740 mov eax,[edi] \u5730\u5740\u5728\u5bc4\u5b58\u5668\u4e2d \u5bc4\u5b58\u5668\u76f8\u5bf9\u5bfb\u5740 mov eax,[edi+20H] \u5e38\u7528\u4e8e\u8bbf\u95ee\u6570\u7ec4\u548c\u7ed3\u6784 \u57fa\u5740\u52a0\u53d8\u5740\u5bfb\u5740 mov eax,[EBP+ESI] \u5e38\u7528\u4e8e\u8bbf\u95ee\u6570\u7ec4 \u76f8\u5bf9\u57fa\u5740\u52a0\u53d8\u5740\u5bfb\u5740 mov eax,[EBX+EDI-10H] \u5e38\u7528\u4e8e\u8bbf\u95ee\u7ed3\u6784"},{"location":"CS/x86assm/#obj-dump","title":"obj dump","text":"\u6e90\u4ee3\u7801\u6587\u4ef6\u540dmytest.c
gcc -c -g -o mytest mytest.c\nobjdump -s -d main.o > main.o.txt\n
\u76ee\u6807\u6587\u4ef6\u53cd\u6c47\u7f16\uff0c\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -c -o main.o main.c\nobjdump -S -d main.o > main.o.txt\n
\u663e\u793a\u6e90\u4ee3\u7801\u7684\u540c\u65f6\u663e\u793a\u884c\u53f7
objdump -j .text -ld -C -S main.o > main.o.txt\n
\u53ef\u6267\u884c\u6587\u4ef6\u53cd\u6c47\u7f16
gcc -o main main.c\nobjdump -s -d main > main.txt\n
\u540c\u65f6\u663e\u793a\u6e90\u4ee3\u7801
gcc -g -o main main.c\nobjdump -S -d main > main.txt\n
"},{"location":"CS/x86assm/#_1","title":"\u671f\u672b\u8003\u8bd5","text":"\u7a0b\u5e8f\u586b\u7a7a\u9898(3\u9898\uff0c\u6bcf\u989810\u5206\uff0c\u517130\u5206)
\u4e00\u822c\u90fd\u4f1a\u7528stack\u538b\u5165\u53c2\u6570 \u4f1a\u7ed9\u51fac\u8bed\u8a00\u7684\u539f\u578b\uff08\uff1f\uff0c\u53c2\u6570\u7684\u538b\u5165\u987a\u5e8f\u4ece\u53f3\u5230\u5de6\uff0ccaller\u6e05\u7406 pascal\uff0c\u4ece\u5de6\u5230\u53f3\uff0ccallee\u6e05\u7406 stdcall\uff0c\u4ece\u53f3\u5230\u5de6\uff0ccaller\u6e05\u7406 \u90fd\u7528ax\u8fd4\u56de\u53c2\u6570 \u4e00\u822c\u4e24\u4e2a\u7a7a\u4e0d\u53ef\u4ee5\u4ea4\u6362\u3002\u3002\u3002 \u5148\u81ea\u5df1\u5199\u4e00\u904d\u518d\u586b \uff08\u4e00\u822c20\u51e0\u884c\u7684\u7a0b\u5e8f\uff09
\u7a0b\u5e8f\u9605\u8bfb(2\u9898\uff0c\u6bcf\u98985\u5206\uff0c\u517110\u5206) \u4f1a\u95ee\u8fd0\u884c\u7ed3\u679c\u548c\u4e2d\u95f4\u7ed3\u679c\uff08#\uff09\uff08\u5982\u679c\u6709\u5faa\u73af\uff0c\u6bcf\u6b21\u5faa\u73af\u5230\u90fd\u8981\u5199\uff0c\u4f46\u662f\u4e0d\u4f1a\u592a\u591a\uff09
\u4e0d\u4f1a\u6709\u76f4\u63a5\u624b\u5199\u4e00\u6574\u4e2a\u7a0b\u5e8f\u7684\u9898
\u91cd\u70b9\uff1a \u51fd\u6570\u53c2\u6570\u4f20\u9012\uff0c\u5982\u4f55\u6784\u9020\u4e00\u4e2a\u5806\u6808\u6846\u67b6\uff0cebp\u3002\u3002 \u9700\u8981\u770b\u61c2\u662f\u4e0d\u662f\u9012\u5f52\uff0c \u6709\u4e00\u4e2a\u7a0b\u5e8f\u586b\u7a7a\u4f1a\u51fa\u5355\u6b65\u8c03\u8bd5\uff0c\u8fb9\u89e3\u5bc6\u8fb9\u52a0\u5bc6\u90a3\u4e2a\u3002\u3002 \u4e0d\u4f1a\u8003\u4fdd\u62a4\u6a21\u5f0f\u3002
"},{"location":"CS/x86assm/#_2","title":"\u590d\u4e60","text":""},{"location":"CS/x86assm/#intel-808680386-cpu","title":"Intel 8086/80386 CPU \u529f\u80fd\u7ed3\u6784","text":""},{"location":"CS/x86assm/#_3","title":"\u5de5\u4f5c\u65b9\u5f0f","text":"\u8fd0\u7b97\u5668\u8fdb\u884c\u4fe1\u606f\u5904\u7406\uff0c\u5bc4\u5b58\u5668\u8fdb\u884c\u4fe1\u606f\u5b58\u50a8\uff0c\u63a7\u5236\u5668\u63a7\u5236\u5404\u79cd\u5668\u4ef6\u5de5\u4f5c\uff0c\u603b\u7ebf\u8fde\u63a5\u5404\u79cd\u5668\u4ef6\u3002
"},{"location":"CS/x86assm/#163280x86-view","title":"16\u4f4d\u548c32\u4f4d\u768480x86\u7684\u533a\u522b - \u64cd\u4f5c\u7cfb\u7edfview","text":"1234h:0058h \u8f6c\u5316\u6210\u7269\u7406\u5730\u5740=12340h+0058h=12398h \u8865\u7801
"},{"location":"CS/x86assm/#_5","title":"\u6807\u5fd7\u4f4d","text":"\u72b6\u6001\u6807\u5fd7\uff1aCF ZF SF OF AF PF \u63a7\u5236\u6807\u5fd7\uff1aDF(direction flags) TF(trace/trap flag) IF(interrupt flag)
"},{"location":"CS/x86assm/#_6","title":"\u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u653e\u89c4\u5f8b\uff1a","text":"\u5c0f\u7aef\u683c\u5f0f\u3002\u4f4e\u5b57\u8282\u5728\u524d\uff0c\u9ad8\u5b57\u8282\u5728\u540e\u3002 \u8bbeds=1000h, bx=2000h, ax=1234h Mov ds:[bx], ax \u6267\u884c\u540e1000:2001\u6307\u5411\u7684\u5b57\u8282=12h
"},{"location":"CS/x86assm/#_7","title":"\u5bc4\u5b58\u5668","text":"\u603b\u7ed3
\u5bc4\u5b58\u5668 \u7c7b\u522b \u7528\u9014 AX \u6570\u636e\u5bc4\u5b58\u5668 \u7b97\u672f\u8fd0\u7b97\u4e2d\u7684\u4e3b\u8981\u5bc4\u5b58\u5668\uff0c\u5728\u4e58\u9664\u8fd0\u7b97\u4e2d\u7528\u6765\u5236\u5b9a\u88ab\u9664\u6570\uff0c\u4e5f\u662f\u4e58\u9664\u8fd0\u7b97\u540e\u7ed3\u679c\u7684\u9ed8\u8ba4\u5b58\u50a8\u5355\u5143\u3002\u53e6\u5916I/O\u6307\u4ee4\u5747\u4f7f\u7528\u8be5\u5bc4\u5b58\u5668\u4e0eI/O\u8bbe\u5907\u4f20\u9001\u4fe1\u606f\u3002 BX \u6570\u636e\u5bc4\u5b58\u5668 \u6307\u4ee4\u5bfb\u5740\u65f6\u5e38\u7528\u505a\u57fa\u5740\u5bc4\u5b58\u5668\uff0c\u5b58\u5165\u504f\u79fb\u91cf\u6216\u504f\u79fb\u91cf\u7684\u6784\u6210\u6210\u5206 CX \u6570\u636e\u5bc4\u5b58\u5668 \u5728\u5faa\u73af\u6307\u4ee4\u64cd\u4f5c\u6216\u4e32\u5904\u7406\u6307\u4ee4\u4e2d\u9690\u542b\u8ba1\u6570 DX \u6570\u636e\u5bc4\u5b58\u5668 \u5728\u53cc\u5b57\u8282\u957f\u8fd0\u7b97\u4e2d\u4e0eAX\u6784\u621032\u4f4d\u64cd\u4f5c\u6570\uff0cDX\u4e3a\u9ad816\u4f4d\u3002\u5728\u67d0\u4e9bI/O\u6307\u4ee4\u4e2d\uff0cDX\u88ab\u7528\u6765\u5b58\u653e\u7aef\u53e3\u5730\u5740 SP \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u59cb\u7ec8\u662f\u6808\u9876\u7684\u4f4d\u7f6e\uff0c\u4e0eSS\u5bc4\u5b58\u5668\u4e00\u8d77\u6784\u6210\u6808\u9876\u6570\u636e\u7684\u7269\u7406\u5730\u5740 BP \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u7cfb\u7edf\u9ed8\u8ba4\u5176\u6307\u5411\u5806\u6808\u4e2d\u67d0\u4e00\u5355\u5143\uff0c\u5373\u63d0\u4f9b\u6808\u4e2d\u8be5\u5355\u5143\u7684\u504f\u79fb\u91cf\u3002\u52a0\u6bb5\u524d\u7f00\u540e\uff0cBP\u53ef\u4f5c\u4e3a\u975e\u5806\u6808\u6bb5\u7684\u5730\u5740\u6307\u9488 SI \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u4e0eDS\u8054\u7528\uff0c\u6307\u793a\u6570\u636e\u6bb5\u4e2d\u67d0\u64cd\u4f5c\u7684\u504f\u79fb\u91cf\u3002\u5728\u505a\u4e32\u5904\u7406\u65f6\uff0cSI\u6307\u793a\u6e90\u64cd\u4f5c\u6570\u5730\u5740\uff0c\u5e76\u6709\u81ea\u52a8\u589e\u91cf\u548c\u81ea\u52a8\u51cf\u91cf\u7684\u529f\u80fd\u3002\u53d8\u5740\u5bfb\u5740\u65f6\uff0cSI\u4e0e\u67d0\u4e00\u4f4d\u79fb\u91cf\u5171\u540c\u6784\u6210\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf DI \u6307\u9488\u53ca\u53d8\u5740\u5bc4\u5b58\u5668 \u4e0eDS\u8054\u7528\uff0c\u6307\u793a\u6570\u636e\u6bb5\u4e2d\u67d0\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf\uff0c\u6216\u4e0e\u67d0\u4e00\u4f4d\u79fb\u91cf\u5171\u540c\u6784\u6210\u64cd\u4f5c\u6570\u7684\u504f\u79fb\u91cf\uff0c\u4e32\u5904\u7406\u64cd\u4f5c\u65f6\uff0cDI\u6307\u793a\u9644\u52a0\u6bb5\u4e2d\u76ee\u7684\u5730\u5740\uff0c\u5e76\u6709\u81ea\u52a8\u589e\u91cf\u548c\u51cf\u91cf\u7684\u529f\u80fd\u3002 CS \u6bb5\u5bc4\u5b58\u5668 \u5b58\u653e\u5f53\u524d\u7a0b\u5e8f\u7684\u6307\u793a\u4ee3\u7801 DS \u6bb5\u5bc4\u5b58\u5668 \u5b58\u653e\u7a0b\u5e8f\u6240\u8bbe\u8ba1\u7684\u6e90\u6570\u636e\u6216\u7ed3\u679c SS \u6bb5\u5bc4\u5b58\u5668 \u4ee5\u201c\u5148\u5165\u540e\u51fa\u201d\u4e3a\u539f\u5219\u7684\u6570\u636e\u533a ES \u6bb5\u5bc4\u5b58\u5668 \u8f85\u52a9\u6570\u636e\u533a\uff0c\u5b58\u653e\u4e32\u6216\u5176\u5b83\u6570\u636e IP \u63a7\u5236\u5bc4\u5b58\u5668 \u5b83\u59cb\u7ec8\u6307\u5411\u5f53\u524d\u5c06\u8981\u6267\u884c\u6307\u4ee4\u5728\u4ee3\u7801\u6bb5\u4e2d\u7684\u504f\u79fb\u91cf FR \u63a7\u5236\u5bc4\u5b58\u5668 \u63a7\u5236\u6807\u5fd7\u4f4d "},{"location":"CS/x86assm/#_8","title":"\u901a\u7528\u5bc4\u5b58\u5668","text":"IA-32\u67b6\u6784\u4e2d\u4e00\u5171\u67094\u4e2a32\u4f4d\u5bc4\u5b58\u5668\uff0c\u7528\u4e8e\u4fdd\u5b58\u4e34\u65f6\u6570\u636e\uff0c\u8fd94\u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u53ef\u4ee5\u5f53\u4f5c16\u4f4d\u7528\uff0c\u4e5f\u53ef\u4ee5\u4f5c8\u4f4d\u7528\u3002
AX BX CX DX\uff1a\u6570\u636e\u5bc4\u5b58\u5668\uff0c\u6bcf\u4e2a\u6570\u636e\u5bc4\u5b58\u5668\u90fd\u53ef\u4ee5\u62c6\u6210\u4e24\u4e2a 8 \u4f4d\u5bc4\u5b58\u5668\u72ec\u7acb\u4f7f\u7528\uff0c\u5982 AX \u53ef\u62c6\u5206\u4e3a AH \u548c AL\uff0cBX \u62c6\u5206\u4e3a BH \u548c BL \u7b49\u3002H \u548c L \u5206\u522b\u8868\u793a\u9ad8 8 \u4f4d\u548c\u4f4e 8 \u4f4d\u3002
AX(accumulator)\uff1a\u7d2f\u52a0\u5668\u3002\u5728\u4e58\u9664\u6cd5\u8fd0\u7b97\u3001\u4e32\u8fd0\u7b97\u3001 I/O \u6307\u4ee4\u4e2d\u90fd\u4f5c\u4e3a\u4e13\u7528\u5bc4\u5b58\u5668\uff1b BX (base)\uff1a\u57fa\u5740\u5bc4\u5b58\u5668\uff0c\u5e38\u7528\u4e8e\u5b58\u6863\u5185\u5b58\u5730\u5740\u3002
CX (count)\uff1a\u8ba1\u6570\u5bc4\u5b58\u5668\u3002\u5e38\u7528\u4e8e\u5b58\u653e\u5faa\u73af\u8bed\u53e5\u7684\u5faa\u73af\u6b21\u6570\uff0c\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u4e5f\u5e38\u7528\u3002
DX (data)\uff1a\u6570\u636e\u5bc4\u5b58\u5668\u3002\u5e38\u5e38\u548cEAX\u4e00\u8d77\u4f7f\u7528\u3002
"},{"location":"CS/x86assm/#_9","title":"\u53d8\u5740\u5bc4\u5b58\u5668","text":"\u5b58\u653e\u5728\u53d8\u52a8\u7684\u5185\u5b58\u5730\u5740
ESI(source index): \u6e90\u53d8\u5740\u5bc4\u5b58\u5668\uff0c\u901a\u5e38\u5b58\u653e\u8981\u5904\u7406\u7684\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u3002
EDI(destination index)\uff1a\u76ee\u7684\u53d8\u5740\u5bc4\u5b58\u5668\uff0c\u901a\u5e38\u5b58\u653e\u5904\u7406\u540e\u7684\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u3002
ESI\u548cEDI\u5e38\u7528\u6765\u914d\u5408\u4f7f\u7528\u5b8c\u6210\u6570\u636e\u7684\u8d4b\u503c\u64cd\u4f5c
rep movs dword ptr[edi], dword ptr[esi];\n
\u8fd9\u53e5\u7684\u610f\u601d\u662f\u628aESI\u6307\u5411\u7684\u5185\u5b58\u5730\u5740\u4e2d\u7684\u5185\u5bb9\u590d\u5236\u5230EDI\u6240\u6307\u5411\u7684\u5185\u5b58\u4e2d\uff0c\u6570\u636e\u957f\u5ea6\u5728ECX\u4e2d\u6307\u5b9a\u3002
"},{"location":"CS/x86assm/#_10","title":"\u6307\u9488\u5bc4\u5b58\u5668","text":"ESP\uff08stack pointer\uff09\uff1a\u5806\u6808\u6307\u9488\u5bc4\u5b58\u5668\u3002SS\uff1aSP\u6307\u5411\u5806\u6808\u7684\u6808\u9876\uff0c\u56e0\u6b64\u867d\u7136\u662f\u901a\u7528\u5bc4\u5b58\u5668\uff0c\u4f46\u4e0d\u5e94\u968f\u4fbf\u6539\u53d8SP\u7684\u503c\u3002\u4e0d\u53ef\u4ee5\u4f5c\u4e3a\u901a\u7528\u5bc4\u5b58\u5668\u4f7f\u7528\uff0cESP\u5b58\u653e\u5f53\u524d\u5806\u6808\u6808\u9876\u7684\u5730\u5740\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cESP\u548cEBP\u8054\u5408\u4f7f\u7528\u6765\u8bbf\u95ee\u51fd\u6570\u4e2d\u7684\u53c2\u6570\u548c\u5c40\u90e8\u53d8\u91cf\u3002 EBP\uff08base pointer\uff09\uff1a\u57fa\u5740\u6307\u9488\u5bc4\u5b58\u5668\u3002\u53ef\u4ee5\u4f5c\u4e3a\u901a\u7528\u5bc4\u5b58\u5668\u7528\u4e8e\u5b58\u653e\u64cd\u4f5c\u6570\uff0c\u5e38\u7528\u6765\u4ee3\u66ff\u5806\u6808\u6307\u9488\u8bbf\u95ee\u5806\u6808\u7684\u6570\u636e\u3002 EIP\uff1a\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668\uff0c\u603b\u662f\u6307\u5411\u4e0b\u4e00\u6761\u8981\u6267\u884c\u7684\u6307\u4ee4\u7684\u5730\u5740\u3002 \u5e38\u89c1\u7684\u8bbf\u95ee\u5806\u6808\u6307\u4ee4\uff1a
push ebp\nmov ebp, esp\nsub esp, 78\npush esi\npush edi\ncmp dword ptr [ebp+8], 0\n
ss\u6808\u6bb5\u5bc4\u5b58\u5668 sp\u6808\u9876\u6307\u9488\u5bc4\u5b58\u5668 bp\u9ed8\u8ba4\u7684\u6808\u5bfb\u5740\u5bc4\u5b58\u5668
"},{"location":"CS/x86assm/#_11","title":"\u6807\u5fd7\u5bc4\u5b58\u5668","text":"\u6807\u5fd7\u5bc4\u5b58\u5668EFLAGS\u4e00\u5171\u670932\u4f4d\uff0c\u5728\u8fd932\u4f4d\u4e2d\u5927\u90e8\u5206\u662f\u4fdd\u7559\u7ed9\u7f16\u5199\u64cd\u4f5c\u7cfb\u7edf\u7684\u4eba\u7528\u7684\u3002
IP (instruction pointer)\uff1a\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668\u3002\u4ee3\u7801\u6bb5\u5bc4\u5b58\u5668 CS \u548c\u6307\u4ee4\u6307\u9488\u5bc4\u5b58\u5668 IP \u662f 8086CPU \u4e2d\u6700\u5173\u952e\u7684\u4e24\u4e2a\u5bc4\u5b58\u5668\u3002\u5b83\u4eec\u5206\u522b\u7528\u6765\u63d0\u4f9b\u5f53\u524d\u6307\u4ee4\u7684\u6bb5\u5730\u5740\u548c\u504f\u79fb\u5730\u5740\u3002\u5373\u4efb\u610f\u65f6\u523b\uff0c8086CPU \u5c06 CS:IP \u6307\u5411\u7684\u5185\u5bb9\u5f53\u505a\u547d\u4ee4\u6267\u884c\u3002\u6bcf\u6761\u6307\u4ee4\u8fdb\u5165\u6307\u4ee4\u7f13\u51b2\u5668\u540e\u3001\u6267\u884c\u524d\uff0cIP += \u6240\u8bfb\u53d6\u6307\u4ee4\u7684\u957f\u5ea6\uff0c\u4ece\u800c\u6307\u5411\u4e0b\u4e00\u6761\u6307\u4ee4\u3002\u7528\u6237\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee IP \u5bc4\u5b58\u5668\u3002
FL (flags)\uff1a\u6807\u5fd7\u5bc4\u5b58\u5668\u3002\u4e0e\u5176\u4ed6\u5bc4\u5b58\u5668\u4e00\u6837\uff0c\u6807\u5fd7\u5bc4\u5b58\u5668\u4e5f\u6709 16 \u4f4d\uff0c\u4f46\u662f\u6807\u5fd7\u5bc4\u5b58\u5668\u53ea\u7528\u5230\u5176\u4e2d\u7684 9 \u4f4d\u3002\u8fd9 9 \u4f4d\u5305\u62ec 6 \u4e2a\u72b6\u6001\u6807\u5fd7\u548c 3 \u4e2a\u63a7\u5236\u6807\u5fd7\uff0c\u53c2\u89c1\u4e0b\u9762\u7684\u201c\u6807\u5fd7\u4f4d\u201d\u3002
OF\uff08Overflow Flag\uff09:\u6ea2\u51fa\u6807\u5fd7\uff0c\u6ea2\u51fa\u65f6\u4e3a1\uff0c\u5426\u5219\u7f6e0\u3002\u4e24\u4e2a\u6b63\u6570\u76f8\u52a0\u53d8\u8d1f\uff0c\u6216\u4e24\u4e2a\u8d1f\u6570\u76f8\u52a0\u53d8\u6b63\u4f1a\u6ea2\u51fa\u3002#
DF \uff08Direction Flag\uff09:\u65b9\u5411\u6807\u5fd7\uff0c\u5728\u4e32\u5904\u7406\u6307\u4ee4\u4e2d\u63a7\u5236\u4fe1\u606f\u7684\u65b9\u5411\u30020:\u6b63\u65b9\u5411\uff0c1\uff1a\u53cd\u65b9\u5411\u3002cld\uff0cstd\u3002#
IF (Interrupt Flag) :\u4e2d\u65ad\u6807\u5fd7\u3002\u7981\u6b62\u4e2d\u65ad0\uff0c\u5141\u8bb8\u4e2d\u65ad1\u3002cli\uff0csti\u3002#
AF (Auxiliary carry Flag) :\u8f85\u52a9\u8fdb\u4f4d\u6807\u5fd7\uff0c\u6709\u8fdb\u4f4d\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
ZF (Zero Flag) :\u96f6\u6807\u5fd7\uff0c\u8fd0\u7b97\u7ed3\u6784\u4e3a0\u65f6ZF\u4f4d\u4f4d\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
SF (Sign Flag):\u7b26\u53f7\u6807\u5fd7\uff0c\u7ed3\u679c\u4e3a\u8d1f\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002#
CF (Carry Flag): \u8fdb\u4f4d\u6807\u5fd7\uff0c\u8fdb\u4f4d\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002\u914d\u5957\u7684clc\uff0cstc\u4e24\u6761\u8bbe\u7f6e\u6307\u4ee4\uff1a\u6e05\u9664\u548c\u7f6e1\u3002#
PF (Parity Flag): \u5947\u5076\u6807\u5fd7\u3002\u7ed3\u679c\u64cd\u4f5c\u6570\u4e2d1\u7684\u4e2a\u6570\u4e3a\u5076\u6570\u65f6\u7f6e1\uff0c\u5426\u5219\u7f6e0\u3002
TF\uff1a\u5355\u6b65\u8c03\u8bd5\u8981\u7528\u3002#
EFLAGS\u662f\u5b9e\u73b0\u6761\u4ef6\u5224\u65ad\u548c\u903b\u8f91\u5224\u65ad\u7684\u4e00\u79cd\u673a\u5236\uff0c\u5728\u6c47\u7f16\u8bed\u8a00\u4e2d\u4e00\u822c\u4e0d\u76f4\u63a5\u8bbf\u95eeEFLAGS\u5bc4\u5b58\u5668\uff0c\u800c\u662f\u901a\u8fc7\u6307\u4ee4\u7684\u64cd\u4f5c\u9690\u542b\u8bbf\u95eeEFLAGS\u5bc4\u5b58\u5668\u3002
cmp dword ptr [ebp+8], 0. // \u5f71\u54cd\u6807\u5fd7\u4f4dCF\uff0cZF\uff0cSF\uff0cOF\uff0cAF\u548cPF\nJz 99495898 //\u5982\u679cZF\u7b49\u4e8e1\uff0c\u5219\u8df3\u8f6c\u523000405898
"},{"location":"CS/x86assm/#_12","title":"\u6307\u4ee4","text":"\u603b\u7ed3
\u6307\u4ee4 \u4f5c\u7528 \u53c2\u6570 \u6539\u53d8\u6807\u5fd7\u4f4d mov \u8d4b\u503c \u88ab\u8d4b\u503c\u5bc4\u5b58\u5668\uff0c\u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\uff0c\u503c\u3011 no xchg \u6570\u636e\u4ea4\u6362 \u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\u3011\uff0c\u3010\u5bc4\u5b58\u5668\uff0c\u5185\u5b58\u3011 no push \u8fdb\u6808 \u6e90\u64cd\u4f5c\u6570\u3010\u5bc4\u5b58\u5668\u3011 pop \u51fa\u6808 \u76ee\u7684\u64cd\u4f5c\u6570\u3010\u5bc4\u5b58\u5668\u3011 pushf \u6807\u5fd7\u4f4d\u8fdb\u6808 \u65e0 popf \u6807\u5fd7\u4f4d\u51fa\u6808 \u65e0 lea Load effect address\uff0c\u5bfb\u5740\uff0c\u53d6\u504f\u79fb\u5730\u5740 lds \u5f53\u6307\u4ee4\u6307\u5b9a\u7684\u662f16\u4f4d\u5bc4\u5b58\u5668\u65f6\uff0c\u628a\u6e90\u64cd\u4f5c\u6570\u5b58\u50a8\u5355\u5143\u4e2d\u5b58\u653e\u7684\u5341\u516d\u4f4d\u504f\u79fb\u5730\u5740\u53d6\u51fa\u5b58\u653e\u5728\u5bc4\u5b58\u5668\u4e2d\uff0c\u7136\u540e\u628a\u6e90\u64cd\u4f5c\u6570+2\u7684\u5341\u516d\u4f4d\u6570\u88c5\u5165\u6307\u4ee4\u6307\u5b9a\u7684\u6bb5\u5bc4\u5b58\u5668\u3002\u5f53\u6307\u4ee4\u6307\u5b9a\u7684\u662f32\u4f4d\u5bc4\u5b58\u5668\u65f6 \u628a\u6e90\u64cd\u4f5c\u6570\u5b58\u50a8\u5355\u5143\u4e2d\u5b58\u653e\u768432\u4f4d\u504f\u79fb\u5730\u5740\u88c5\u5165\u5bc4\u5b58\u5668 \u7136\u540e\u628a \u6e90\u64cd\u4f5c\u6570+4 \u768416\u4f4d\u6570\u88c5\u5165\u6bb5\u5bc4\u5b58\u5668\u3002mem\u6307\u5411\u7684\u5730\u5740,\u9ad8\u4f4d\u5b58\u653e\u5728DS\u4e2d,\u4f4e\u4f4d\u5b58\u653e\u5728reg\u4e2d. LDS reg,mem les \u628a\u5185\u5b58\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u7684\u53cc\u5b57\u64cd\u4f5c\u6570\u7684\u4f4e\u4f4d\u5b57\u88c5\u5165\u6307\u4ee4\u4e2d\u6307\u5b9a\u7684\u5bc4\u5b58\u5668\u3001\u9ad8\u4f4d\u5b57\u88c5\u5165ES\u5bc4\u5b58\u5668\u3002 cbw 8\u4f4d\u6570\u6269\u5c55\u4e3a16\u4f4d\u6570\uff0c\u6709\u7b26\u53f7\u6269\u5145 no cwd \u5b57(16\u4f4d)\u6269\u5c55\u4e3a\u53cc\u5b57(32\u4f4d)\uff0c\u6709\u7b26\u53f7\uff1f no add \u52a0 OPRDS\uff0cOPRDD adc \u5e26\u8fdb\u4f4d\u52a0\uff08\u7ed3\u679c\u542b\u6807\u5fd7\u4f4dCF\u7684\u503c\uff0c=OPRDS\uff0bOPRDD\uff0bCF\uff09 OPRDS\uff0cOPRDD sub \u51cf OPRDD\uff0cOPRDS sbb \u5e26\u8fdb\u4f4d\u51cf\uff08\u7ed3\u679c\u542b\u6807\u5fd7\u4f4dCF\u7684\u503c\uff0c=OPRDD\uff0dOPRDS\uff0dCF\uff09 OPRDD\uff0cOPRDS inc \u81ea\u589e1 \u5bc4\u5b58\u5668 dec \u81ea\u51cf1 \u5bc4\u5b58\u5668 mul 32\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aEAX\uff0c\u90a3\u4e48\u4e58\u79ef\u5c06\u5b58\u653e\u5728EDX\uff1aEAX\u4e2d 32\u4f4d\u4e58\u6570 16\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aAX\u90a3\u4e48\u4e58\u79ef\u5c06\u653e\u5728DX\uff1aAX\u4e2di 16\u4f4d\u4e58\u6570 8\u4f4d\uff1a\u88ab\u4e58\u6570\u9ed8\u8ba4\u4e3aAL\uff0c\u90a3\u4e48\u4e58\u79ef\u5c06\u653e\u5728AX 8\u4f4d\u4e58\u6570 div 32\u4f4d\uff1a\u88ab\u9664\u6570\u5c06\u662fEDX\uff1aEAX\uff0c \u6700\u7ec8\u7684\u5546\u5c06\u5b58\u653e\u5728EAX\uff0c \u4f59\u6570\u5c06\u5b58\u653e\u5728EDX\u4e2d 32\u4f4d\u4e58\u6570 16\u4f4d\uff1a\u88ab\u9664\u6570\u4e3aEAX\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u5546\u653e\u5728AX\uff0c\u4f59\u6570\u653e\u5728EAX\u7684\u9ad816\u4f4d 16\u4f4d\u4e58\u6570 8\u4f4d\uff1a\u88ab\u9664\u6570\u662f16\u4f4d\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u5546\u5c06\u653e\u5728AL\u4e2d\uff0c\u4f59\u6570\u653e\u5728AH\u4e2d 8\u4f4d\u4e58\u6570 imul \u65e0\u7b26\u53f7\u4e58 idiv \u65e0\u7b26\u53f7\u9664 xlat \u6362\u7801\u6307\u4ee4\uff0c\u4ee5bx\u4e3a\u9996\u5730\u5740\u7684\uff0c\u504f\u79fb\u5730\u5740\u4e3aal\u7684\u5185\u5bb9\u9001\u7ed9al\u3002 in \u7aef\u53e3\u8bfb\u5199\u6307\u4ee4 IN AL,21H\uff1b\u8868\u793a\u4ece21H\u7aef\u53e3\u8bfb\u53d6\u4e00\u5b57\u8282\u6570\u636e\u5230AL out \u7aef\u53e3\u8bfb\u5199\u6307\u4ee4 and \u6309\u4f4d\u4e0e or \u6309\u4f4d\u6216 xor \u6309\u4f4d\u5f02\u6216 not \u64cd\u4f5c\u6570\u6309\u4f4d\u53d6\u53cd neg \u64cd\u4f5c\u6570\u6309\u4f4d\u53d6\u53cd\u52a0\u4e00 test \u5bf9\u4e24\u4e2a\u64cd\u4f5c\u6570\u8fdb\u884c\u6309\u4f4d\u4e0e\u64cd\u4f5c\u3002\u4e0eand\u4e0d\u540c\uff0c\u4e0d\u5f71\u54cd\u76ee\u6807\u64cd\u4f5c\u6570\u7684\u503c\u3002 shl \u903b\u8f91\u5de6\u79fb\uff0c\u5c06\u4e00\u4e2a\u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u6216\u5355\u5143\u4e2d\u7684\u6570\u636e\u5411\u5de6\u79fb\u4f4d\uff0c\u5c06\u6700\u540e\u79fb\u51fa\u7684\u4e00\u4f4d\u5199\u5165cf\u4e2d\u3002\u6700\u4f4e\u4f4d\u75280\u8865\u5145\u3002 shr \u903b\u8f91\u53f3\u79fb\uff0c\u5c06\u4e00\u4e2a\u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u6216\u5355\u5143\u4e2d\u7684\u6570\u636e\u5411\u5de6\u79fb\u4f4d\uff0c\u5c06\u6700\u540e\u79fb\u51fa\u7684\u4e00\u4f4d\u5199\u5165cf\u4e2d\u3002\u6700\u9ad8\u4f4d\u75280\u8865\u5145\u3002 sal \u7b97\u672f\u5de6\u79fb\uff0c\u4e0eshl\u4e00\u6837\uff0c\u88650 sar \u7b97\u672f\u53f3\u79fb\uff0c\u4e0eshr\u4e0d\u4e00\u6837\uff0c\u7b97\u672f\u53f3\u79fb\u8865\u6700\u9ad8\u4f4d rol \u5faa\u73af\u5de6\u79fb ror \u5faa\u73af\u53f3\u79fb rcl \u5e26\u8fdb\u4f4d\u5faa\u73af\u5de6\u79fb\uff0c\u5de6\u79fb\u7684\u65f6\u5019\u79fb\u51fa\u53bb\u7684\u4f1a\u653e\u5728cf\uff1f rcr \u5e26\u8fdb\u4f4d\u5faa\u73af\u53f3\u79fb cmp \u6bd4\u8f83 ja jump if above jb Jump if below jae Jump if above or equal jbe Jump if below or equal jg jump if greater\uff0c\u6709\u7b26\u53f7\u5927\u4e8e\u8df3\u8f6c jl jump less\uff0c\u6709\u7b26\u53f7\u5c0f\u4e8e\u8df3\u8f6c jge jump if greater or equal jle Jump if less or equal jc jump if with carry, CF = 1 jnc jump if not with carry, CF = 0 je = jz jump if equal, ZF = 1 jne = jnz jump if not equal, ZF = 0 jz jump if zero, ZF = 1 jnz jump if not zero, ZF = 0 jcxz jump if cx equals zero js SF = 1 jns SF = 0 jo Jump if overflow, OF = 1 jno jump if not overflow, OF = 0 loop \u5faa\u73af \u4ee3\u7801\u6bb5\uff08\uff1f\uff09\u540d clc clear carry flag\uff0c\u5c06cf\u4f4d\u6e05\u96f6 stc set carry flag\uff0cCF\u7f6e1 cli clear interrupt endable flag\uff0cIF\u6e05\u96f6\uff0c\u5173\u95ed\u4e2d\u65ad sti set interrupt endable flag\uff0cIF\u7f6e\u4f4d1\uff0c\u6253\u5f00\u4e2d\u65ad CMC complement carry flag\uff0cCF\u53d6\u53cd CLD clear direction flag\uff0cDF\u6e05\u96f6 STD set interrupt endable flag\uff0cDF\u7f6e1 call \u8fd1\u8c03\u7528 ret \u8fd1\u8fd4\u56de call far ptr \u8fdc\u8c03\u7528\u3002\u4e09\u4e2apush\u4e00\u4e2ajmp\u3002push f\uff0cpush cs\uff0cpush ip\uff0cjump retf \u8fdc\u8fd4\u56de\u3002\u4e09\u4e2apop\u3002\u6307\u4ee4\u2f64\u6808\u4e2d\u7684\u6570\u636e\uff0c\u4fee\u6539CS\u548cIP\u7684\u5185\u5bb9\uff0c\u4ece\u2f7d\u5b9e\u73b0\u8fdc\u8f6c\u79fb int \u4e2d\u65ad\u6307\u4ee4 iret \u4e2d\u65ad\u8fd4\u56de jmp short \u6bb5\u5185\u77ed\u8f6c\u79fb\uff0c\u77ed\u662f\u6307\u8981\u8df3\u2f84\u7684\u2f6c\u6807\u5730\u5740\u4e0e\u5f53\u524d\u5730\u5740\u524d\u540e\u76f8\u5dee\u4e0d\u8d85\u8fc7128\u5b57\u8282 jmp near ptr \u6bb5\u5185\u8fd1\u8f6c\u79fb\u3002\u8fd1\u662f\u6307\u8df3\u8f6c\u7684\u2f6c\u6807\u5730\u5740\u4e0e\u5f53\u524d\u5730\u5740\u5728\u2f64\u2f00\u4e2a\u6bb5\u5185\uff0c\u5373CS\u7684\u503c\u4e0d\u53d8\uff0c\u53ea\u6539\u53d8EIP\u7684\u503c jmp far ptr \u6bb5\u95f4\u8f6c\u79fb\uff0c\u8fdc\u6307\u8df3\u5230\u53e6\u2f00\u4e2a\u4ee3\u7801\u6bb5\u53bb\u6267\u2f8f\uff0cCS/EIP\u90fd\u8981\u6539\u53d8 Jmp dword ptr \u6bb5\u95f4\u8f6c\u79fb\uff0c\u4ee5\u5185\u5b58\u5730\u5740\u5355\u5143\u5904\u7684\u53cc\u5b57\u6765\u4fee\u6539\u6307\u4ee4\uff0c\u2fbc\u5730\u5740\u5185\u5bb9\u4fee\u6539CS\uff0c\u4f4e\u5730\u5740\u5185\u5bb9 \u4fee\u6539IP\uff0c\u5185\u5b58\u5730\u5740\u53ef\u4ee5\u4ee5\u4efb\u4f55\u5408\u6cd5\u7684\u2f45\u5f0f\u7ed9\u51fa repe/renpe scasb \u5b57\u7b26\u4e32\u626b\u63cf\u6307\u4ee4\u3002cmp al, es:[di] di++; \u5f53DF=1\u65f6\uff0c\u4e3adi-- repne:\u5f53ECX!=0\u5e76\u4e14ZF==0\u65f6 \u91cd\u590d repe: cx != 0\u4e14zf != 0\u91cd\u590d repe/renpe cmpsb \u5b57\u7b26\u4e32\u6bd4\u8f83\u6307\u4ee4\u3002\u2f50\u8f83byte ptr ds:[si]\u4e0ebyte ptr es:[di] \u5f53DF=0\u65f6\uff0cSI++\uff0cDI++ \u5f53DF=1\u65f6\uff0cSI--\uff0cDI-- repne:\u5f53ECX!=0\u5e76\u4e14ZF==0\u65f6 \u91cd\u590d repe: cx != 0\u4e14zf != 0\u91cd\u590d rep movsb \u5b57\u7b26\u4e32\u79fb\u52a8\u6307\u4ee4\u3002\u5176\u4e2drep\u8868\u793arepeat\uff0cs\u8868\u793astring\uff0cb\u8868\u793abyte \u5728\u6267\u2f8f\u6b64\u6307\u4ee4\u524d\u8981\u505a\u4ee5\u4e0b\u51c6\u5907\u2f2f\u4f5c\uff1a \u2460ds:si lodsb \u5757\u88c5\u5165\u6307\u4ee4\uff0c\u628aSI\u6307\u5411\u7684\u5b58\u50a8\u5355\u5143\u8bfb\u5165\u7d2f\u52a0\u5668\uff0clodsb\u5c31\u8bfb\u5165ax\uff0clodsw\u5c31\u8bfb\u5165ax\uff0c\u7136\u540esi\u81ea\u52a8\u589e\u52a0\u6216\u51cf\u5c0f1\u62162 stosb/stosw/stosd SI\u6307\u5411\u7684https://baike.baidu.com/item/%E5%AD%98%E5%82%A8%E5%8D%95%E5%85%83\u8bfb\u5165https://baike.baidu.com/item/%E7%B4%AF%E5%8A%A0%E5%99%A8,\u5176\u4e2dLODSB\u662f\u8bfb\u5165AL, LODSW\u662f\u8bfb\u5165AX\u4e2d, \u7136\u540eSI\u81ea\u52a8\u589e\u52a0\u6216\u51cf\u5c0f1\u62162\u4f4d.\u5f53\u65b9\u5411\u6807\u5fd7\u4f4dDF=0\u65f6\uff0c\u5219SI\u81ea\u52a8\u589e\u52a0\uff1bDF=1\u65f6\uff0cSI\u81ea\u52a8\u51cf\u5c0f\u3002 rep stosb lodsb"},{"location":"CS/x86assm/#_13","title":"\u6570\u636e\u4f20\u9001\u6307\u4ee4","text":"\u6570\u636e\u4f20\u9001\u6307\u4ee4\u662f\u4e3a\u4e86\u5b9e\u73b0CPU\u548c\u5185\u5b58\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u7aef\u53e3\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9001\u3002
mov
mov eax, 56 // \u5c0656H\u4f20\u9001\u5230eax\u5bc4\u5b58\u5668\nmov esi, dword ptr [eax * 2 + 1] // \u5c06\u5185\u5b58\u5730\u5740\u4e3aeax*2+1\u76844\u5b57\u8282\u6570\u636e\u4f20\u9001\u5230esi\u5bc4\u5b58\u5668\nmov ah, byte ptr [esi * 2 + eax] // \u5c06\u5185\u5b58\u5730\u5740\u4e3aesi*+eax\u5904\u76848\u4f4d\u6570\u636e\u4f20\u9001\u5230AH\u5bc4\u5b58\u5668\n
xchg
\u5bc4\u5b58\u5668\u548c\u5185\u5b58\u7684\u6570\u636e\u4ea4\u6362\uff0c\u4ea4\u6362\u7684\u6570\u636e\u53ef\u4ee5\u662f8\u5b57\u8282\u300116\u5b57\u8282\u621632\u5b57\u8282\uff0c\u5fc5\u987b\u683c\u5f0f\u76f8\u540c
xchg eax, edx; // \u5c06edx\u5bc4\u5b58\u5668\u7684\u503c\u548ceax\u5bc4\u5b58\u5668\u7684\u503c\u4ea4\u6362\nxchg [esp-55], edi; // \u5c06edi\u5bc4\u5b58\u5668\u7684\u503c\u548c\u5806\u6808\u5730\u5740\u4e3a[esp-55]\u5904\u7684\u503c\u4ea4\u6362\n
push pop
push\u548cpop\uff1a\u79f0\u4e3a\u538b\u5165\u5806\u6808\u6307\u4ee4\u548c\u5f39\u51fa\u5806\u6808\u6307\u4ee4\uff0c\u683c\u5f0f\u662fpush src(\u6e90\u64cd\u4f5c\u6570)\u548cpop dst(\u76ee\u7684\u64cd\u4f5c\u6570)\uff0cpush\u6307\u4ee4\u548cpop\u6307\u4ee4\u9700\u8981\u5339\u914d\u51fa\u73b0\uff0c\u5426\u5219\u5806\u6808\u4f1a\u4e0d\u5e73\u8861\u3002push\u6307\u4ee4\u5c06\u539f\u64cd\u4f5c\u6570src\u538b\u5165\u5806\u6808\uff0c\u540c\u65f6esp-4\uff08\u6808\u9876\u6307\u9488\u51cf\u4e00\u4e2a4\u4f4d\uff09\uff0c\u800cpop\u53cd\u4e4b\uff0c\u4ece\u5806\u6808\u7684\u9876\u90e8\u5f39\u51fa4\u5b57\u8282\u7684\u6570\u503c\u7136\u540e\u653e\u5165dst\u3002\u572832\u4f4d\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0cpush\u548cpop\u7684\u64cd\u4f5c\u662f\u4ee54\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\uff0cpush\u548cpop\u6307\u4ee4\u5e38\u7528\u4e8e\u5411\u51fd\u6570\u4f20\u53c2\u3002
push eax // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u4ee54\u5b57\u8282\u538b\u5165\u5806\u6808\uff0c\u540c\u65f6esp-4\npush dword ptr [12FF8589] // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230\u5185\u5b58\u5730\u5740\u4e3a12FF8589\u6240\u6307\u5730\u65b9\uff0c\u540c\u65f6esp+4\n-----------------------------------------------------------------------------\npop dword ptr [12FF8589] // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230\u5185\u5b58\u5730\u5740\u4e3a12FF8589\u6240\u6307\u7684\u5730\u65b9\uff0c\u540c\u65f6esp+4\npop eax // \u5c06\u5806\u6808\u9876\u90e8\u76844\u5b57\u8282\u5f39\u51fa\u5230eax\u5bc4\u5b58\u5668\uff0c\u540c\u65f6esp+4\n
"},{"location":"CS/x86assm/#_14","title":"\u5730\u5740\u4f20\u9001\u6307\u4ee4","text":"x86\u67093\u6761\u5730\u5740\u4f20\u9001\u6307\u4ee4\uff0c\u5206\u522b\u662fLEA\uff0cLDS\u548cLES\u3002\u5176\u5b9eLDS\u548cLES\u6307\u4ee4\u548c\u6bb5\u5bc4\u5b58\u5668\u6709\u5173\uff0c\u572832\u4f4d\u7684windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u4e00\u822c\u7684\u7a0b\u5e8f\u5458\u90fd\u4e0d\u9700\u8981\u7ba1\u7406\u6bb5\u5bc4\u5b58\u5668\uff0c\u6240\u4ee5\u76f8\u5bf9\u800c\u8a00\uff0cLDS\u548cLES\u5bc4\u5b58\u5668\u4f7f\u7528\u5f97\u6bd4\u8f83\u5c11\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u5e38\u89c1\u7684\u53ea\u6709LEA\u6307\u4ee4\u3002
LEA
\u79f0\u4e3a\u5730\u5740\u4f20\u9001\u6307\u4ee4\uff0c\u683c\u5f0f\u662f\u201cLEA DST, ADDR\u201d\u3002LEA\u5c06ADDR\u5730\u5740\u52a0\u8f7d\u5230DST\uff0c\u5176\u4e2dADDR\u53ef\u4ee5\u662f\u5185\u5b58\uff0c\u4e5f\u53ef\u4ee5\u662f\u5bc4\u5b58\u5668\uff0c\u800cDST\u5fc5\u987b\u662f\u4e00\u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u3002
lea eax, [12345678]; // \u6307\u4ee4\u6267\u884c\u540eeax\u5bc4\u5b58\u5668\u7684\u503c\u4e3a12345678H\nmov eax, [12345678]; // \u800cmov eax, [12345678] \u6307\u4ee4\u6267\u884c\u540eeax\u5bc4\u5b58\u5668\u7684\u503c\u4e3a\u5185\u5b58\u5730\u574012345678\u6307\u5411\u7684\u90a3\u4e2a\u6570\u503c\n// LEA\u6307\u4ee4\u53ef\u7528\u4e8e\u7b97\u6cd5\u8fd0\u7b97\nlea ecx, [ecx + eax*4]; // ecx = ecx + eax * 4\n// \u76f8\u5f53\u4e8e\u8ba1\u7b97\u51faecx+eax*4\u7684\u6570\u503c\uff0c\u5728[]\u91cc\u662f\u4e00\u4e2a\u5730\u5740\uff0clea\u53d6\u5730\u5740\u540e\u5c31\u53d6\u5230\u4e86\u8fd9\u4e2a\u6570\u503c\n
"},{"location":"CS/x86assm/#_15","title":"\u7b97\u6570\u8fd0\u7b97\u6307\u4ee4","text":"80x86\u63d0\u4f9b\u4e868\u6761\u52a0\u51cf\u6cd5\u6307\u4ee4\uff0c4\u6761\u4e58\u9664\u6cd5\u6307\u4ee4\u3002
ADD\uff1a\u52a0\u6cd5\u6307\u4ee4
add eax, esi; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u52a0\u4e0aesi\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u7684\u5bc4\u5b58\u5668\u4e2d\nadd ebx, dword ptr[12345678] // \u5c06ebx\u5bc4\u5b58\u5668\u7684\u503c\u52a0\u4e0a\u5185\u5b58\u5730\u5740\u4e3a12345678\u6240\u5728\u76844\u5b57\u8282\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728ebx\u5bc4\u5b58\u5668\u4e2d\n// \u4e0d\u540c\u7684\u5e73\u53f0\u548c\u7f16\u8bd1\u5668\u4e2d\uff0cdword\u5360\u7528\u7684\u5b57\u8282\u6570\u4e0d\u540c\uff0c\u572832\u4f4d\u7684windows\u4e2d\u4e00\u4e2aword\u536016\u5b57\u8282\uff0cdword\u536032\u5b57\u8282\n// 64\u4f4d\u4e2d\u4e00\u4e2aword\u536032\u5b57\u8282\uff0cdword\u536064\u5b57\u8282\n
sub \u51cf\u6cd5\u6307\u4ee4
sub ecx, 4H; // \u5c06ecx\u5bc4\u5b58\u5668\u7684\u503c\u51cf\u53bb4H\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\nsub byte ptr[eax], ch; // \u5c06\u5185\u5b58\u5730\u5740\u4e3aeax\u6240\u6307\u5411\u7684\u6570\u636e\u7ed3\u6784\u6309\u5b57\u8282\u4e3a\u5355\u4f4d\u548cch\u5bc4\u5b58\u5668\u76f8\u51cf\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u6309\u5b57\u8282\u4e3a\u5355\u4f4d\u4fdd\u5b58\u5728eax\u6240\u6307\u5411\u7684\u4f4d\u7f6e\n
inc\u52a01\u6307\u4ee4
inc eax; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u52a01\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u653e\u5728\u539f\u6765\u7684\u5730\u65b9\n
dec\u51cf1\u6307\u4ee4
dec edx; // \u5c06dec\u5bc4\u5b58\u5668\u7684\u503c\u51cf1\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u653e\u5728\u539f\u6765\u7684\u5730\u65b9\n
cmp\u6bd4\u8f83\u6307\u4ee4
\u79f0\u6bd4\u8f83\u6307\u4ee4\u683c\u5f0f\u662f\u201dcmp oper1, oper2\u201d
cmp\u6307\u4ee4\u5c06oper1\u51cf\u53bboper2\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4e0d\u4fdd\u5b58\uff0c\u53ea\u662f\u76f8\u5e94\u5730\u8bbe\u7f6e\u5bc4\u5b58\u5668eflags\u7684cf\uff0cpf\uff0czf\uff0caf\uff0csf\u548cof\u3002\u4e5f\u5c31\u662f\u8bf4\u53ef\u4ee5\u901a\u8fc7\u6d4b\u8bd5\u5bc4\u5b58\u5668eflags\u76f8\u5173\u7684\u6807\u5fd7\u503c\u5f97\u77e5cmp\u6267\u884c\u540e\u7684\u7ed3\u679c
cmp eax, 56H; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u51cf\u53bb56H\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4e0d\u4fdd\u5b58\uff0c\u5e76\u4e14\u8bbe\u7f6e\u5bc4\u5b58\u5668eflags\u76f8\u5173\u7684\u6807\u5fd7\u4f4d\n
neg
neg\uff1a\u53d6\u8865\u6307\u4ee4\uff0c\u683c\u5f0f\u662fneg oper
neg\u6307\u4ee4\u5c06oper\u64cd\u4f5c\u6570\u53d6\u53cd\uff0c\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\u5c060\u51cf\u53bboper\u64cd\u4f5c\u6570\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5b58\u5728oper\u81ea\u8eab\u4e2d\u3002
neg eax; \n
mul imul
\u65e0\u7b26\u53f7\u4e58\u6cd5\u6307\u4ee4\u548c\u6709\u7b26\u53f7\u4e58\u6cd5\u6307\u4ee4\u3002mul\u6307\u4ee4\u9690\u542b\u4e86\u4e00\u4e2a\u53c2\u52a0\u8fd0\u7b97\u7684\u64cd\u4f5c\u6570eax\u5bc4\u5b58\u5668\uff0c\u5c06eax\u5bc4\u5b58\u5668\u91cc\u7684\u503c\u4e58oper\uff0c\u7ed3\u679c\u4fdd\u5b58\u5728eax\u4e2d\u3002\u5982\u679c\u7ed3\u679c\u8d85\u8fc732\u4f4d\u5219\u9ad832\u4f4d\u4f7f\u7528edx\u5bc4\u5b58\u5668\u4fdd\u5b58\uff0ceax\u5bc4\u5b58\u5668\u4fdd\u5b58\u4f4e32\u4f4d\u3002
mul edx; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u4e58\u4ee5edx\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\n
div idiv
\u9664\u6cd5\u6307\u4ee4\u548c\u6709\u7b26\u53f7\u9664\u6cd5\u6307\u4ee4\u3002
div ecx; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u63094\u5b57\u8282\u4e3a\u5355\u4f4d\u9664\u4ee5ecx\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5546\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u4f59\u6570\u4fdd\u5b58\u5728edx\u5bc4\u5b58\u5668\u4e2d\u3002\ndiv word ptr [esp+36]; // \u5c06eax\u5bc4\u5b58\u5668\u7684\u503c\u6309word\u4e3a\u5355\u4f4d\u9664\u4ee5\u5806\u6808\u5730\u5740\u4e3aesp+36\u6240\u6307\u5411\u7684\u6570\u636e\uff0c\u5f97\u51fa\u7684\u7ed3\u679c\u5546\u4fdd\u5b58\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u4f59\u6570\u4fdd\u5b58\u5728edx\u5bc4\u5b58\u5668\u4e2d\u3002\n
"},{"location":"CS/x86assm/#80386","title":"\u9ad8\u7ea7\u8bed\u8a00\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u4e0e80386\u95f4\u63a5\u5bfb\u5740","text":"BX BP SI DI
BX\uff1a
BP\uff1a
SI\uff1a
DI\uff1a
\u95f4\u63a5\u5bfb\u5740\uff1abx\uff0cbp\uff0csi\uff0cdi\uff0c\u53ef\u4ee5\u653e\u5728\u65b9\u62ec\u53f7\u5185
\u7f3a\u7701\u6bb5\u5740\uff1ads\u548css\uff0c\u5982\u679c\u65b9\u62ec\u53f7\u5185\u6709bp\uff0c\u4e00\u5b9a\u662fss\uff0cbx\u4e00\u5b9a\u662fds
CS (code segment): \u4ee3\u7801\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u4ee3\u7801\u6bb5\u7684\u6bb5\u5730\u5740\u3002
DS (data segment)\uff1a\u6570\u636e\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u6570\u636e\u6bb5\u7684\u6bb5\u5730\u5740\u3002
SS (stack segment)\uff1a\u5806\u6808\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u50a8\u5806\u6808\u6bb5\u7684\u6bb5\u5730\u5740\u3002
ES (extra segment)\uff1a\u9644\u52a0\u6570\u636e\u6bb5\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u5b58\u653e\u9644\u52a0\u6bb5\u7684\u6bb5\u5730\u5740\u3002\u6709\u65f6\uff0c\u4e00\u4e2a\u6570\u636e\u6bb5\u4e0d\u591f\u7528\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e\u4e00\u4e2a\u9644\u52a0\u6bb5\u6765\u5b58\u653e\u66f4\u591a\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e 2 \u4e2a\u6570\u636e\u6bb5\uff0c\u5206\u522b\u7528 DS \u548c ES \u6307\u5411\u3002
\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c\u65f6\uff0cDOS \u4f1a\u628a ds \u548c es \u8d4b\u503c\u4e3a psp(program segment prefix) \u6bb5\u5730\u5740\u3002psp \u6bb5\u4f4d\u4e8e\u7a0b\u5e8f\u9996\u4e2a\u6bb5\u7684\u524d\u9762\uff0c\u957f\u5ea6\u4e3a 100h \u5b57\u8282\uff0c\u5176\u7528\u9014\u662f\u4fdd\u5b58\u5f53\u524d exe \u76f8\u5173\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u5982 psp:80h \u5f00\u59cb\u5b58\u653e\u4e86 exe \u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002
\u95f4\u63a5\u5bfb\u5740\uff1a \u53ef\u4ee5\u2f64\u4f5c\u95f4\u63a5\u5bfb\u5740\u7684\u5bc4\u5b58\u5668\u53ea\u6709\u56db\u4e2a\uff1abx, bp, si, di [bx], [bp], [si], [di]\u662f\u6700\u7b80\u5355\u7684\u95f4\u63a5\u5bfb\u5740 [bx + si], [bp + si], [bx + di], [bp + di]\u6ce8\u610f\u524d\u2faf\u5fc5\u987b\u662fbx/bp\uff0c\u540e\u2faf\u5fc5\u987b\u662fdi/si [bx+2] [bp-2] [si+1] [di-1] [bx+si+2] [bx+di-2]
[bp+si+1] [bp+di-1] tips\uff1a\u4e24\u4e2a\u5bc4\u5b58\u5668\u76f8\u52a0\u7684\u95f4\u63a5\u5bfb\u5740\u2f45\u5f0f\u4e2d, bx\u6216bp\u901a\u5e38\u2f64\u6765\u8868\u793a\u6570\u7ec4\u7684\u2fb8\u5730\u5740, \u2f7dsi\u6216di\u5219\u2f64\u6765\u8868\u793a\u4e0b \u6807\u3002
\u7f3a\u7701\u6bb5\u5740\uff1a\u4e0d\u542bbp\u7684\u6e90\u64cd\u4f5c\u6570\u2f00\u822c\u90fd\u7701\u7565\u7684\u6bb5\u5730\u5740ds\uff0c\u542b\u6709bp\u7684\u6e90\u64cd\u4f5c\u6570\u7701\u7565\u4e86ss\uff0c\u2f7d\u8fd9\u4e2a\u9ed8\u8ba4\u7684\u6bb5\u5730\u5740\u662f \u53ef\u4ee5\u88ab\u6539\u53d8\u7684
\u7528\u5806\u6808\u4f20\u9012\u53c2\u6570\u65f6\uff0c\u5982\u4f55\u7528[bp+]\u5b9e\u73b0\u5bf9\u53c2\u6570\u7684\u5f15\u7528\uff1f
bp + \u591a\u5c11\u5c31\u662f\u6808\u91cc\u7684\u591a\u5c11
\u738b\u723d\u300a\u6c47\u7f16\u8bed\u2f94\u300b\u7b2c\u56db\u7248 \u9644\u5f554:\u2f64\u6808\u4f20\u9012\u53c2\u6570
difcube:\n mov bp, sp\n mov ax, [bp+4] ;a\u7684\u503c\u9001\u5165ax\u4e2d\n sub ax, [bp+6] ;\u51cf\u6808\u4e2db\u7684\u503c\n mov bp, ax\n mul bp\n mul bp\n pop bp\n ret 4\n
"},{"location":"CS/x86assm/#_16","title":"\u5176\u5b83\u7684\u7b14\u8bb0","text":""},{"location":"CS/x86assm/#x86_1","title":"x86\uff1a","text":"Intel\u4ece16\u4f4d\u5fae\u5904\u7406\u56688086\u5f00\u59cb\u7684\u6574\u4e2aCPU\u82af\u7247\u7cfb\u5217\uff0c\u7cfb\u5217\u4e2d\u7684\u6bcf\u79cd\u578b\u53f7\u90fd\u4fdd\u6301\u4e0e\u4ee5\u524d\u7684\u5404\u79cd\u578b\u53f7\u517c\u5bb9\uff0c\u4e3b\u8981\u67098086\uff0c8088\uff0816\u4f4dCPU\uff09\uff0c80186\uff0c80286\uff08\u8fd9\u4e24\u4e2a\u662f\u8fc7\u6e21\u4ea7\u54c1\uff09\uff0c 80386\uff0c80486\u4ee5\u53ca\u4ee5\u540e\u5404\u79cd\u578b\u53f7\u7684Pentium\u82af\u7247\uff0832\u4f4dCPU\uff09\uff0c\u901a\u5e38\u6240\u8bf4\u7684x86\u90fd\u662f\u630732\u4f4dCPU
80386: 32\u4f4d\u6c47\u7f16\u3002
80836\u5bc4\u5b58\u5668
\u901a\u7528\u5bc4\u5b58\u5668(EAX EBX ECX EDX,ESP,EBP,ESI,EDI)
\u901a\u7528\u5bc4\u5b58\u5668\u4e0e8086\u7684\u5bc4\u5b58\u5668\u76f8\u6bd4,\u753116\u4f4d\u53d8\u4e3a\u4e8632\u4f4d
ESP:\u6808\u9876
EBP:\u6808\u5e95
EAX\uff0cEBX\uff0cECX\uff0cEDX\u901a\u7528\u5bc4\u5b58\u5668
EAX\uff1a\u7d2f\u52a0\u5668\uff08\u4e58\u6cd5\u7684\u65f6\u5019\u5b58\u4f4e\u4f4d\uff09
EBX\uff1a\u57fa\u5740\uff08\uff3bEBX\uff0b100\uff28\uff3d\uff09
ECX\uff1a\u8ba1\u6570\uff08\u5faa\u73af\u7684\u65f6\u5019\u8ba1\u6570\uff09
EDX\uff1a\u6570\u636e\uff08\u9ed8\u8ba4EDX\uff0a10H\uff0b\uff0e\uff0e\uff0e\uff1b\u4e58\u6cd5\u7684\u65f6\u5019\u5b58\u9ad8\u4f4d\uff09
ESI\uff0cEDI\uff1a\u53d8\u5740\u5bc4\u5b58\u5668
ESI\uff1a\u6e90\u53d8\u5740\u5bc4\u5b58\u5668
EDI\uff1a\u76ee\u7684\u53d8\u5740\u5bc4\u5b58\u5668\u3000\u4e0eEBX\u57fa\u5740\u642d\u914d\u4f7f\u7528
"},{"location":"CS/x86assm/#_17","title":"\u53c2\u8003\u6587\u732e","text":"asm_sum.doc
xxjj\u7684\u300a\u6c47\u7f16\u8bed\u8a00\u8003\u8bd5\u603b\u7ed3\u300b https://www.yuque.com/xianyuxuan/coding/mkte6u
[80386]80x86\u6c47\u7f16\u6307\u4ee4_CarlosX\u7684\u535a\u5ba2-CSDN\u535a\u5ba2_80386\u6307\u4ee4\u96c6
80386 \u7b97\u672f\u8fd0\u7b97\u6307\u4ee4\uff0c\u903b\u8f91\u8fd0\u7b97\u6307\u4ee4\uff0c\u79fb\u4f4d\u6307\u4ee4 (\u4e09) _ttzyanswer\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/CPP/copy/","title":"\u62f7\u8d1d Copy","text":"\u6d45\u62f7\u8d1d\uff08\u9ed8\u8ba4\u62f7\u8d1d\u51fd\u6570\uff09\uff1a\u5c06\u539f\u5bf9\u8c61\u6216\u539f\u6570\u7ec4\u7684\u5f15\u7528\u76f4\u63a5\u8d4b\u503c\u7ed9\u65b0\u5bf9\u8c61\u3001\u65b0\u6570\u7ec4\uff0c\u65b0\u5bf9\u8c61/\u65b0\u6570\u7ec4\u53ea\u662f\u539f\u5bf9\u8c61\u7684\u4e00\u4e2a\u5f15\u7528\u3002 \u6df1\u62f7\u8d1d\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u548c\u6570\u7ec4\uff0c\u5c06\u539f\u5bf9\u8c61\u7684\u5404\u9879\u5c5e\u6027\u7684\u201c\u503c\u201d\uff08\u6570\u7ec4\u91cc\u7684\u6240\u6709\u5143\u7d20\uff09\u62f7\u8d1d\u8fc7\u6765\u3002\u662f\u201c\u503c\u201d\u800c\u4e0d\u662f\u5f15\u7528\u3002
\u4f7f\u7528\u65f6\u6ce8\u610f\uff1a \u6df1\u62f7\u8d1d\u4f1a\u5728\u5806\u5185\u5b58\u91cc\u53e6\u5916\u7533\u8bf7\u7a7a\u95f4\u6765\u50a8\u5b58\u6570\u636e\uff0c\u4ece\u800c\u89e3\u51b3\u4e86\u6307\u9488\u60ac\u6302\u95ee\u9898\u3002\u5f53\u6570\u636e\u6210\u5458\u4e2d\u6709\u6307\u9488\u65f6\uff0c\u5fc5\u987b\u4f7f\u7528\u6df1\u62f7\u8d1d\u3002
\u6df1\u62f7\u8d1d\u7684\u5199\u6cd5
class MyString\n{\nprivate:\nchar *str;\npublic:\nMyString(const char *p=nullstr)//\u7f3a\u7701\u6784\u9020\u51fd\u6570\n:str(nullptr)\n{\nif(p!=nullptr)\n{\nint len=strlen(p)+1;\nstr=new char[len];\nstrcpy_s(str,lrn,p);\n}\n}\nMyString(const MyString& ms)//\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff0c\u6df1\u62f7\u8d1d\n{\nint n = strlen(ms.str) + 1;\n*str = new char[n];\nstrcpy_s = (str, n, ms.str);\n//int *str\n// this->str=new int(*ms.str)\n}\n~MyString()//\u6790\u6784\u51fd\u6570\n{\n}\n}\uff1b\n
"},{"location":"CS/CPP/course/","title":"Courses \u542c\u8bfe","text":""},{"location":"CS/CPP/course/#cs106bcs106l","title":"\u5173\u4e8eCS106B\u548cCS106L","text":"CS106B\u504f\u7b80\u5355\uff0c\u76f8\u5f53\u4e8eZJU\u7684\u6570\u636e\u7ed3\u6784+C++\u7684STL\u7528\u6cd5\u4e00\u5757\u8bb2\uff0c\u53e6\u5916\u518d\u8bb2\u4e00\u4e9bFDS\u7684\u7b97\u6cd5\u3002 CS106L\u662f\u4e13\u95e8\u8bb2C++\u8fdb\u9636\u7279\u6027\u7684\u3002
\u56e0\u4e3a\u5728\u542cCS106B\u4e4b\u524d\u5b66\u8fc7FDS\uff0cCS106B\u82b1\u4e00\u5929\u901f\u901a\u4e86\u4e00\u4e0b\uff0c\u91cd\u590d\u5185\u5bb9\u6709\u70b9\u591a\uff0c\u622a\u4e0b\u4e86\u4e00\u5e45\u56fe\u3002
CS106L\u63d0\u4f9b\u7684C++\u5b66\u4e60\u8def\u7ebf\u56fe
"},{"location":"CS/CPP/course/#zju","title":"ZJU\u8bfe\u7a0b","text":""},{"location":"CS/CPP/course/#_1","title":"\u8bfe\u7a0b\u53c2\u8003\u8d44\u6599","text":"CPP Reference Standard C++ CppCon
"},{"location":"CS/CPP/course/#_2","title":"\u4e0a\u8bfe\u5fc3\u5f97","text":"\u6211\u8ddf\u7684\u662fcx\u8001\u5e08\u7684\u73ed\uff0c\u5e94\u8be5\u662f\u6559\u5f97\u6700\u597d\u7684\u4e00\u6863orz \u4f46\u662f\u4e0a\u8bfe\u5185\u5bb9\u4ecd\u4e0d\u80fd\u8986\u76d6\u4f5c\u4e1a\u548c\u671f\u672b\u7684\u5185\u5bb9\uff0c\u89c9\u5f97\u542c\u8bfe\u5185\u5bb9\u53ea\u80fd\u8d77\u5230\u4e00\u4e2a\u9aa8\u67b6\u4f5c\u7528\uff0c\u8bfe\u540e\u9700\u8981\u82b1\u4e0a\u8bfe2\u81f33\u500d\u7684\u65f6\u95f4\u81ea\u5b66\u81ea\u5df1\u6574\u7406\u7b14\u8bb0\uff0c\u591a\u8bfb\u591a\u5199\u4ee3\u7801\uff0c\u4e0d\u7136\u671f\u672b\u4f1a\u9047\u5230\u6ca1\u89c1\u8fc7\u7684\u7279\u6027\uff0c\u4f1a\u6709\u70b9\u60e8orz\uff08\u50cf\u6211\u4e00\u6837\uff09
"},{"location":"CS/CPP/course/#_3","title":"\u9762\u5411\u5bf9\u8c61\u56db\u5927\u7279\u6027","text":"class Name\n{\n public:\n public_data;\n public_functions;\n protected:\n protected_data;\n protected_functions;\n private:\n private_data;\n private_functions;\n}\n
\u8fd4\u56de\u7c7b\u578b \u7c7b\u540d::\u6210\u5458\u51fd\u6570\u540d\uff08\u53c2\u6570\u8868\uff09 { // \u51fd\u6570\u4f53 }
"},{"location":"CS/CPP/course/#_9","title":"\u5185\u8054\u51fd\u6570\u548c\u5916\u8054\u51fd\u6570","text":"\u53ef\u4ee5\u628a\u76f8\u540c\u6570\u636e\u7ed3\u6784\u548c\u76f8\u540c\u64cd\u4f5c\u96c6\u7684\u5bf9\u8c61\u770b\u4f5c\u5c5e\u4e8e\u540c\u4e00\u7c7b\u3002\u5bf9\u8c61\u662f\u7c7b\u7684\u5b9e\u4f8b\u3002
"},{"location":"CS/CPP/course/#_11","title":"\u5bf9\u8c61\u7684\u5b9a\u4e49","text":"\u5bf9\u8c61\u540d.\u6570\u636e\u6210\u5458\u540d\uff08\u662f \u5bf9\u8c61\u540d.\u7c7b\u540d::\u6210\u5458\u540d \u7684\u7f29\u5199\uff09 \u5bf9\u8c61\u540d.\u6210\u5458\u51fd\u6570\u540d\uff08\u53c2\u6570\u8868\uff09
class Sample\n{\npublic:\nint k;\nint geti(){return i;}\nint getj(){return j;}\nint getk(){return k;}\nprivate:\nint i;\nprotected:\nint j;\n};\nint main()\n{\nSample a;\na.i; // \u975e\u6cd5\na.j: // \u975e\u6cd5\na.k; // \u5408\u6cd5\n}\n
"},{"location":"CS/CPP/course/#_13","title":"\u7c7b\u7684\u4f5c\u7528\u57df","text":"\u7c7b\u7684\u6784\u9020\u51fd\u6570\u662f\u7c7b\u7684\u4e00\u4e2a\u7279\u6b8a\u6210\u5458\u51fd\u6570\uff0c\u6ca1\u6709\u8fd4\u56de\u7c7b\u578b\uff08\u4e0d\u662fvoid\uff09\uff0c\u53ef\u4ee5\u6709\u53c2\u6570\uff0c\u51fd\u6570\u540d\u548c\u7c7b\u540d\u4e00\u6837\u3002\u5f53\u521b\u5efa\u7c7b\u7684\u4e00\u4e2a\u65b0\u5bf9\u8c61\u65f6\uff0c\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570\uff0c\u5b8c\u6210\u521d\u59cb\u5316\u5de5\u4f5c\u3002
"},{"location":"CS/CPP/course/#namespace","title":"Namespace","text":""},{"location":"CS/CPP/course/#namespace_1","title":"\u4ec0\u4e48\u662fnamespace\uff1f","text":"\u662f\u5355\u4e00\u7684\u5168\u5c40\u540d\u5b57\u7a7a\u95f4\u3002\u9632\u6b62\u5728\u4e00\u4e2a\u7a7a\u95f4\u4e2d\u76f8\u540c\u7684\u540d\u5b57\u5f15\u8d77\u51b2\u7a81\u3002 \u4f8b\u5b50\uff1a
namespace myown1\n{\nstring user_name = \"myown1\";\n}\nnamespace myown2\n{\nstring user_name = \"myown2\";\n}\nint main()\n{\n// using namespace myown1; \ncout << \"\\\\n\" << \"Hello, \"\n<< myown1::user_name\n<< \"...and goodbye!\\\\n\"\ncout << \"\\\\n\" << \"Hello, \"\n<< myown2::user_name\n<< \"...and goodbye!\\\\n\"\nreturn 0;\n}\n
\u5173\u952e\u8bcdusing\u5c06\u4e00\u4e2a\u540d\u5b57\u7a7a\u95f4\u53d8\u4e3a\u53ef\u89c1\uff0c\u4e0d\u4f1a\u8986\u76d6\u5f53\u524d\u7684namespace\u3002
"},{"location":"CS/CPP/course/#_15","title":"\u7ee7\u627f\u4e0e\u6d3e\u751f\u7c7b","text":"\u6d3e\u751f\u7c7b\u7ee7\u627f\u4e86\u57fa\u7c7b\u4e2d\u9664\u6784\u9020\u51fd\u6570\u548c\u6790\u6784\u51fd\u6570\u4e4b\u5916\u7684\u6240\u6709\u6210\u5458\u3002\u6d3e\u751f\u7c7b\u7684\u6210\u5458\u5305\u62ec\uff1a - \u7ee7\u627f\u57fa\u7c7b\u7684\u6210\u5458 - \u6d3e\u751f\u7c7b\u5b9a\u4e49\u65f6\u58f0\u660e\u7684\u6210\u5458
\u4ece\u5df2\u6709\u7c7b\u6d3e\u751f\u51fa\u65b0\u7c7b\u65f6\uff0c\u53ef\u4ee5\u5728\u6d3e\u751f\u7c7b\u5185\u5b8c\u6210\u4ee5\u4e0b\u51e0\u79cd\u529f\u80fd\uff1a - \u589e\u52a0\u65b0\u7684\u6570\u636e\u6210\u5458 - \u589e\u52a0\u65b0\u7684\u6210\u5458\u51fd\u6570 - \u91cd\u65b0\u5b9a\u4e49\u57fa\u7c7b\u4e2d\u5df2\u6709\u7684\u6210\u5458\u51fd\u6570 - \u53ef\u4ee5\u6539\u53d8\u73b0\u6709\u6210\u5458\u7684\u5c5e\u6027
\u58f0\u660e\u4e00\u4e2a\u6d3e\u751f\u7c7b\u7684\u4e00\u822c\u683c\u5f0f
class \u6d3e\u751f\u7c7b\u540d:\u7ee7\u627f\u65b9\u5f0f \u57fa\u7c7b\u540d\n{\n// \u6d3e\u751f\u7c7b\u65b0\u589e\u7684\u6570\u636e\u6210\u5458\u548c\u6210\u5458\u51fd\u6570\n};\n
\u4e09\u79cd\u7ee7\u627f\u65b9\u5f0f
class employee: public person\n{};\n// default\nclass employee: private person\n{};\nclass employee: protected person\n{};\n
\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027
\u5728\u57fa\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027 \u7ee7\u627f\u65b9\u5f0f \u5728\u6d3e\u751f\u7c7b\u4e2d\u7684\u8bbf\u95ee\u5c5e\u6027 \u89e3\u91ca private public inaccessible \u57fa\u7c7b\u4e2dprivate\u7684\u5bf9\u8c61\u5728\u7c7b\u5916\u5f53\u7136\u4e0d\u53ef\u8bbf\u95ee private private inaccessible private protected inaccessible public public public \u57fa\u7c7b\u4e0d\u7ba1 public private private public protected protected protected public protected \u6743\u9650\u4f1a\u88ab\u7ee7\u627f\u65b9\u5f0f\u7f29\u5c0f\u800c\u4e0d\u4f1a\u653e\u5927 protected private private protected protected protected\u6d3e\u751f\u7c7b\u5bf9\u57fa\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219 - \u5185\u90e8\u8bbf\u95ee\uff1a\u7531\u6d3e\u751f\u7c7b\u4e2d\u65b0\u589e\u6210\u5458\u5bf9\u57fa\u7c7b\u7ee7\u627f\u6765\u7684\u6210\u5458\u7684\u8bbf\u95ee\u3002 - \u5bf9\u8c61\u8bbf\u95ee\uff1a\u5728\u6d3e\u751f\u7c7b\u5916\u90e8\uff0c\u901a\u8fc7\u6d3e\u751f\u7c7b\u7684\u5bf9\u8c61\u5bf9\u4ece\u57fa\u7c7b\u7ee7\u627f\u6765\u7684\u6210\u5458\u7684\u8bbf\u95ee\u3002
\u57fa\u7c7b\u6210\u5458 private\u6210\u5458 public\u6210\u5458 protected\u6210\u5458 \u5185\u90e8\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u53ef\u8bbf\u95ee \u53ef\u8bbf\u95ee \u5bf9\u8c61\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee \u4e0d\u53ef\u8bbf\u95ee\u79c1\u6709\u7ee7\u627f\u4e3e\u4f8b
class Point\n{\npublic:\nvoid InitP(float x = 0, float y = 0)\n{\nthis->X = x;\nthis->Y = y;\n}\nvoid Move(float offX, float offY)\n{\nX += offX;\nY += offY;\n}\nfloat GetX() const{return X;}\nfloat GetY() const{return Y;}\nprivate:\nfloat X, Y;\n};\nclass Rectangle: private Point // \u6d3e\u751f\u7c7b\u58f0\u660e\n{\npublic: //\u65b0\u589e\u5916\u90e8\u63a5\u53e3\nvoid InitR(float x, float y, float w, float h)\n{\nInitR(x, y);\nW = w;\nH = h;\n} // \nvoid Move(float xOff, float yOff)\n{\nPoint::\n}\n}\n
"},{"location":"CS/CPP/file_io/","title":"\u6587\u4ef6\u8bfb\u5199 File IO","text":"#include <fstream>\n
ifstream fin;\nofstream fout;\n
\u6587\u4ef6\u6253\u5f00\u65b9\u5f0f
ios::in \u53ea\u8bfb ios::out \u53ea\u5199 ios::app \u4ece\u6587\u4ef6\u672b\u5c3e\u5f00\u59cb\u5199 ios::binary \u4e8c\u8fdb\u5236\u6a21\u5f0f"},{"location":"CS/CPP/final_review/","title":"ZJU \u671f\u672b\u590d\u4e60","text":"\u9762\u5411\u671f\u672b\u9898\u7684\u76f8\u4f3c\u77e5\u8bc6\u70b9\u805a\u7c7b
"},{"location":"CS/CPP/final_review/#_1","title":"\u6784\u9020\u987a\u5e8f","text":"\uff081\uff09main\u51fd\u6570\u4ee5\u5916\u7684\u5bf9\u8c61\uff0c\u5168\u5c40\u7c7b\u5b9a\u4e49\u540e\u76f4\u63a5\u5b9a\u4e49\u7684\u7c7b\u5bf9\u8c61 \uff082\uff09main\u51fd\u6570\u5185\u7684\u5bf9\u8c61 \uff083\uff09\u7236\u7c7b\u6784\u9020 \uff084\uff09\u5b50\u7c7b\u7c7b\u6210\u5458 \uff085\uff09\u5b50\u7c7b\u6784\u9020 \u6790\u6784\u987a\u5e8f\u76f8\u53cd
"},{"location":"CS/CPP/final_review/#_2","title":"\u4ec0\u4e48\u65f6\u5019\u751f\u6210\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff1f","text":"\u5982\u679c\u5df2\u7ecf\u6709\u6784\u9020\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u4e0d\u4f1a\u751f\u6210\u9ed8\u8ba4\u6784\u9020\u51fd\u6570 \u6ca1\u6709\u7684\u65f6\u5019\u4e5f\u4e0d\u4e00\u5b9a\u4f1a\u751f\u6210 \u9700\u8981\u7528\u624d\u751f\u6210
"},{"location":"CS/CPP/final_review/#_3","title":"\u91cd\u8f7d\u89c4\u5219","text":"\u4e0d\u80fd\u91cd\u8f7d\u7684\u6709\uff1a - \u4f5c\u7528\u57df\u64cd\u4f5c\u7b26:: - \u6761\u4ef6\u64cd\u4f5c\u7b26?:\uff08\u5e94\u8be5\u662f\u95ee\u53f7\u8868\u8fbe\u5f0f\uff1f\uff09 - \u70b9\u64cd\u4f5c\u7b26\u3001\u7c7b\u6210\u5458\u6307\u9488 - \u9884\u5904\u7406\u7b26\u53f7#
\u53ea\u80fd\u91cd\u8f7d\u4e3a\u53cb\u5143\u4e0d\u80fd\u6210\u5458\u51fd\u6570\uff1a - <<\u548c>> \u539f\u56e0\u662f\u6210\u5458\u51fd\u6570\u91cd\u8f7d\uff0c\u53ea\u80fd\u5e26\u4e00\u4e2a\u53c2\u6570\uff0clhs\u5fc5\u987b\u662f\u6210\u5458\u81ea\u8eab
\u4f46\u662f\u6d41\u64cd\u4f5c\u7b26\u5de6\u8fb9\u662fcin\u6216cout\uff0c\u91cd\u8f7d\u4e3a\u53cb\u5143\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u6bd4\u6210\u5458\u51fd\u6570\u591a\u8bf4\u660e\u4e00\u4e2a\u5f62\u53c2\u505alhs
\u91cd\u8f7d\u548c\u91cd\u5199\u90fd\u662f\u591a\u6001\uff1a \u91cd\u8f7d\uff1a\u8fd0\u884c\u65f6\u591a\u6001 \u91cd\u5199\uff1a\u7f16\u8bd1\u65f6\u591a\u6001
static\u548cvirtual\u53ea\u80fd\u6709\u4e00\u4e2a
\u6790\u6784\u51fd\u6570\u4e0d\u80fd\u5e26\u53c2\u6570
"},{"location":"CS/CPP/final_review/#_4","title":"\u5b50\u7c7b\u548c\u7236\u7c7b\u6307\u9488","text":"\u4ec0\u4e48\u65f6\u5019\u5fc5\u987b\u7528\u5e38\u5f15\u7528\uff08const &\uff09\uff1a\u5f15\u7528\u578b\u53c2\u6570\u5e94\u5f53\u5728\u80fd\u5b9a\u4e49\u4e3aconst\u7684\u60c5\u51b5\u4e0b\u5c3d\u91cf\u5b9a\u4e49\u4e3aconst\u3002
\u4f7f\u7528\u5f15\u7528\u7684\u4e3b\u8981\u539f\u56e0\uff1a \u7a0b\u5e8f\u80fd\u591f\u4fee\u6539\u8c03\u7528\u51fd\u6570\u4e2d\u7684\u6570\u636e\u5bf9\u8c61 \u901a\u8fc7\u4f20\u9012\u5f15\u7528\u800c\u4e0d\u662f\u6574\u4e2a\u6570\u636e\u5bf9\u8c61\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6
\u53ea\u4f7f\u7528\u4f20\u9012\u8fc7\u6765\u7684\u503c\u800c\u4e0d\u4fee\u6539 \u9700\u8981\u4fee\u6539\u4f20\u9012\u8fc7\u6765\u7684\u503c \u5185\u7f6e\u6570\u636e\u7c7b\u578b\uff08\u5c0f\u578b\u7ed3\u6784\uff09 \u6309\u503c\u4f20\u9012 \u6307\u9488\u4f20\u9012 \u6570\u7ec4 \u6307\u9488\u4f20\u9012 \u6307\u9488\u4f20\u9012 \u8f83\u5927\u7684\u7ed3\u6784\uff09 \u6307\u9488\u6216\u5f15\u7528 \u6307\u9488\u6216\u5f15\u7528 \u7c7b/\u5bf9\u8c61 \u5f15\u7528\u4f20\u9012 \u5f15\u7528\u4f20\u9012\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\uff1a \u53ef\u4ee5\u628a\u5f15\u7528\u7406\u89e3\u6210\u4e00\u4e2a\u5e38\u91cf\u6307\u9488\uff0c\u56e0\u6b64\u5f15\u7528\u58f0\u660e\u65f6\u5c31\u5fc5\u987b\u521d\u59cb\u5316\uff0c\u4e00\u7ecf\u58f0\u660e\u4e0d\u80fd\u518d\u548c\u5176\u5b83\u5bf9\u8c61\u7ed1\u5b9a\u3002
Copy constructor must pass its first argument by reference
"},{"location":"CS/CPP/final_review/#_6","title":"\u7c7b\u5185\u9759\u6001\u6210\u5458\u7684\u521d\u59cb\u5316","text":"const static\u53ef\u4ee5\u5728\u7c7b\u5185\u76f4\u63a5\u521d\u59cb\u5316\uff0c\u975econst static\u6210\u5458\u9700\u8981\u5728\u7c7b\u5916\u521d\u59cb\u5316\u3002
\u53ef\u4ee5\u8c03\u7528\u9ed8\u8ba4\u521d\u59cb\u5316A::n\uff0c\u81ea\u52a8\u521d\u59cb\u5316\u4e3a0\u3002\u6b64\u65f6\u8c03\u7528\u9ed8\u8ba4\u6784\u9020\u4e0d\u80fd\u7528n()\uff0c\u5426\u5219\u8ba4\u4e3a\u662f\u4e2a\u51fd\u6570\u3002\u6216\u8005\u5e26\u521d\u59cb\u503c\u521d\u59cb\u5316A::n(9)
static\u548cconst - \u6ca1\u6709static\u5c31\u662fconst\u7684\u8bf4\u6cd5
const\u7684\u51e0\u79cd\u5f62\u5f0f
const int& fun(int& a); // \u4fee\u9970\u8fd4\u56de\u503c \nint& fun(const int& a); // \u4fee\u9970\u5f62\u53c2 \nint& fun(int& a) const {} // const\u6210\u5458\u51fd\u6570\n
const\u8fd4\u56de\u503c\uff1a\u662f\u4fee\u9970\u8fd4\u56de\u503c\u5f15\u7528\u7c7b\u578b\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u907f\u514d\u8fd4\u56de\u503c\u88ab\u4fee\u6539\u7684\u60c5\u51b5
\u8fd4\u56de\u503c\u662f\u5f15\u7528\u7684\u51fd\u6570\uff0c\u8fd9\u4e2a\u5f15\u7528\u5fc5\u7136\u4e0d\u662f\u4e34\u65f6\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4e00\u5b9a\u662f\u6210\u5458\u53d8\u91cf\u6216\u8005\u51fd\u6570\u53c2\u6570\u3002\uff08\u53ea\u8981\u53c2\u6570\u4e0d\u9700\u8981\u4fee\u6539\u4e00\u5b9a\u52a0\u4e0aconst\uff09
const\u53c2\u6570\u5fc5\u987b\u4f20\u7b7e\u540d\u540e\u5e26const\u7684\u51fd\u6570\uff1a\u8981\u628athis\u6307\u9488\u53d8\u6210const
\u600e\u6837\u6784\u6210\u91cd\u8f7d - \u4e0d\u91cd\u8f7d\u7684
const int& fun(int& a); // \u53c2\u6570\u5217\u8868\u6ca1\u6709\u53d8 \nint& fun(const int a); // \u56e0\u4e3a\u662f\u503c\u4f20\u9012\uff0c\u4e0d\u662fconst\u7684\u4e5f\u80fdtype conversion\n
int& fun(const int& a); // \u56e0\u4e3a\u662f\u53d8\u91cf\u4f20\u9012\uff0c\u8981\u6c42\u68c0\u67e5\u53c2\u6570\u7684const\uff0c\u662f\u53c2\u6570\u5217\u8868\u53d8\u4e86 \nint& fun(int& a) const {} // \u56e0\u4e3a\u9690\u542b\u53c2\u6570this\u7684const\u4e0e\u5426\u4e0d\u4e00\u6837\uff0c\u4e5f\u662f\u53c2\u6570\u5217\u8868\u53d8\u4e86\n
\u200b\u4ee3\u66ff\u5b8f\u7684\u4e00\u79cd\u64cd\u4f5c\uff0c\u5728\u7f16\u8bd1\u9636\u6bb5\u628a\u6240\u6709\u51fd\u6570\u540d\u66ff\u6362\u6210inline function\u7684\u5b9e\u73b0 \u6bd4\u51fd\u6570\u7684\u4f18\u70b9\uff1a\u4e0d\u7528\u9891\u7e41\u8fdb\u6808\u51fa\u6808 \u6bd4\u5b8f\u7684\u4f18\u70b9\uff1a\u6709\u7c7b\u578b\u68c0\u67e5\uff0c\u80fd\u5199\u591a\u884c\uff0c\u80fd\u64cd\u4f5c\u7c7b\u7684\u79c1\u6709\u6210\u5458 inline\u5173\u952e\u5b57\u53ea\u6709\u51fa\u73b0\u5728\u51fd\u6570\u7684\u5b9a\u4e49\u800c\u4e0d\u662f\u58f0\u660e\u524d\u65f6\u624d\u6709\u7528\u3002 \u9759\u6001\u7ed1\u5b9a\u00a0Static\u00a0Binding \u3002\u80fd\u591f\u660e\u786e\u8fd0\u884c\u7684\u662f\u54ea\u4e2a\u7c7b\u7684\u65b9\u6cd5\u65f6\u4f1a\u53d1\u751f\u9759\u6001\u7ed1\u5b9a \u3002\u53d1\u751f\u5728\u7f16\u8bd1\u65f6\u523b\uff0c\u6240\u4ee5\u53c8\u53eb\u65e9\u7ed1\u5b9a \u52a8\u6001\u7ed1\u5b9aDynamic\u00a0Binding \u3002\u51fa\u73b0\u591a\u6001\uff0c\u7f16\u8bd1\u5668\u4e0d\u80fd\u660e\u786e\u5230\u5e95\u4f7f\u7528\u54ea\u4e2a\u7c7b\u7684\u65b9\u6cd5\u65f6\u53d1\u751f\u52a8\u6001\u7ed1\u5b9a \u3002\u53d1\u751f\u5728\u8fd0\u884c\u65f6\u523b\uff0c\u6240\u4ee5\u53c8\u53eb\u665a\u7ed1\u5b9a \u3002\u53ea\u6709\u5b58\u5728\u00a0virtual\u00a0\u65e6\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u65f6\uff0c\u624d\u4f1a\u53d1\u751f\u52a8\u6001\u7ed1\u5b9a
static binding \u7f16\u8bd1\u65f6
class Animal { public: void eat() { cout << \"Animal eats\" << endl; } }; class Dog : public Animal { public: void eat() { cout << \"Dog eats\" << endl; } };\n
dynamic binding \u8fd0\u884c\u65f6
class Animal { public: virtual void eat() { cout << \"Animal eats\" << endl; } }; class Dog : public Animal { public: void eat() { cout << \"Dog eats\" << endl; } };\n
\u200b \u5728\u4e0b\u9762\u7684\u60c5\u51b5\u4e0b\uff0c\u6784\u9020\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff1a - \u5bf9\u4e8e\u5168\u5c40\u5bf9\u8c61\uff0c\u5728main()\u4e24\u6570\u8fd0\u884c\u4e4b\u524d\uff0c\u6216\u8005\u5728\u540c\u4e00\u4e2a\u7f16\u8bd1\u5355\u5143\u5185\u5b9a\u4e49\u7684\u4efb\u4e00\u51fd\u6570\u6216\u5bf9\u8c61 \u88ab\u4f7f\u7528\u4e4b\u524d\u3002\u5728\u540c\u4e00\u4e2a\u7f16\u8bd1\u5355\u5143\u5185\uff0c\u5b83\u4eec\u7684\u6784\u9020\u4e24\u6570\u6309\u7167\u58f0\u660e\u7684\u987a\u5e8f\u521d\u59cb\u5316\u3002 - \u5bf9\u4e8e static\u00a0local\u00a0variables\uff0c\u00a0\u5728\u7b2c\u4e00\u6b21\u8fd0\u884c\u5230\u5b83\u7684\u58f0\u660e\u7684\u65f6\u5019. - \u5bf9\u4e8e automatic\u00a0storage\u00a0duration\u00a0\u7684\u5bf9\u8c61\uff0c\u5728\u5176\u58f0\u660e\u88ab\u8fd0\u884c\u65f6\u3002 - \u5bf9\u4e8e dynamic\u00a0storage\u00a0duration\u00a0\u7684\u5bf9\u8c61\uff0c\u5728\u5176\u7528\u00a0new\u00a0\u8868\u8fbe\u5f0f\u521b\u5efa\u65f6\u3002
"},{"location":"CS/CPP/final_review/#_7","title":"\u667a\u80fd\u6307\u9488","text":"std::unique_ptr<T> //\u72ec\u5360\u8d44\u6e90\u6240\u6709\u6743\u7684\u6307\u9488\u3002 \nstd::shared_ptr<T> //\u5171\u4eab\u8d44\u6e90\u6240\u6709\u6743\u7684\u6307\u9488\u3002 \nstd::weak_ptr<T> //\u5171\u4eab\u8d44\u6e90\u7684\u89c2\u5bdf\u8005\uff0c\u9700\u8981\u548cstd::shared_ptr \u4e00\u8d77\u4f7f\u7528\uff0c\u4e0d\u5f71\u54cd\u8d44\u6e90\u7684\u751f\u547d\u5468\u671f\u3002\n
\u4f7f\u7528\u88f8\u6307\u9488 \u6240\u4ee5\u9ed8\u8ba4\u53c2\u6570\u662f\u548c\u865a\u8868\u65e0\u5173\u4e0e\u5f53\u524d\u7c7b\u578b\u6709\u5173\u5417 \u662f\u7684 \u9ed8\u8ba4\u53c2\u6570\u4e0d\u8fdb\u865a\u8868 \u2192 upcasting\u7684\u65f6\u5019
"},{"location":"CS/CPP/final_review/#upcasting","title":"upcasting","text":"is_a \u903b\u8f91
#include <...>\nclass B{\npublic:\nint f(int i) {cout << \"f(int)\"; return i+1; }\n};\nclass D: public B{\npublic:\nusing B::f; // \u4fdd\u8bc1\u4e0d\u4f1a\u8986\u76d6\u6389B\u4e2d\u7684f\ndouble f(double d) }\n
\u8bbf\u95ee\u63a7\u5236\uff1aprivate\u548cprotected\u7ee7\u627f
int a;\nclass X{\nint a;\n};\nclass XX: public X{\nvoid }\n
\u865a\u7ee7\u627f
\u5411\u4e0a\u8f6c\u578b
Base *pb = &derived;\n
\u8fd9\u4e2a\u4e0d\u4e00\u5b9a\u53ef\u884c
Shape s = c; // object slicing\ns = c; // copy assignment\n
virtual \u5173\u952e\u5b57
\u8bf4\u660e\u4e00\u4e2a non-static member function \u662f\u4e00\u4e2a virtual function
\u884c\u4e3a\u53ef\u4ee5\u88ab\u6d3e\u751f\u7c7boverride\uff08\u91cd\u5199/\u8986\u76d6\uff09
Base::vf\uff0c\u5b50\u7c7b\u6709\u4e00\u4e2a\u540d\u5b57\u3001\u53c2\u6570\u5217\u8868
struct Base {\nvirtual void print() {cout << \"Base\\\\n\"; }\n};\nstruct Derived: public Base{\nvoid }\n
virtual call \u53ea\u5173\u5fc3\u5bf9\u8c61\u7684\u7c7b\u578b\uff0ccall\u5bf9\u5e94\u7c7b\u7684\u51fd\u6570
\u53ea\u8981\u8c03\u7528\u865a\u51fd\u6570\u5c31\u662f\u865a\u8c03\u7528
virtual void do_draw() = 0; // \u662f\u7eaf\u865a\u51fd\u6570\uff0c\u4e0d\u5fc5\u6709\u5b9e\u73b0\uff0c\u4f46\u662f\u53ef\u4ee5\u6709\u5b9e\u73b0\n
\u5982\u679c\u6709\u81f3\u5c11\u4e00\u4e2a\u7eaf\u865a\u51fd\u6570\uff0c\u662f\u62bd\u8c61\u7c7b\uff0c\u62bd\u8c61\u7c7b\u4e0d\u80fd\u7528\u4e8e\u58f0\u660e\u6210\u5458\uff0c\u53ea\u80fd\u4f5c\u4e3a\u57fa\u7c7b
final \u5173\u952e\u5b57\uff1a\u4e0d\u80fd\u88ab\u91cd\u5199\uff0c\u4e0d\u80fd\u88ab\u7ee7\u627f
\u865a\u51fd\u6570\u7684\u901a\u5e38\u5b9e\u73b0\uff1avirtual table (vtable)
static vtable \u865a\u8868
class Der: public Base {\npublic:\nvirtual arbiturary_return_type vir0{}\nvirtual arbiturary_return_type vir1{}\nvirtual arbiturary_return_type vie2{}\n}\n
\u5b83\u7684\u865a\u51fd\u6570\u8868
FunctionPtr Der::__vtable[5]{\n&Der::vir0, &Der::vir1, &Der::vir2, &Base::vir3, &Base::vir4\n}\n
\u597d\u50cf\u5b9e\u9645\u4e0a\u76f8\u5f53\u4e8e\u8fd9\u4e48call\u7684
b.__vptr[3](b);\n
template\u548cOOP\u7684\u533a\u522b\uff0c\u8bed\u4e49\u4e0d\u4e00\u6837\u3002
"},{"location":"CS/CPP/namespace/","title":"\u547d\u540d\u7a7a\u95f4 Namespace","text":"\u547d\u540d\u7a7a\u95f4\uff1a \u540d\u79f0name\u53ef\u4ee5\u662f\u7b26\u53f7\u5e38\u91cf\uff0c\u53d8\u91cf\uff0c\u51fd\u6570\uff0c\u7ed3\u6784\uff0c\u679a\u4e3e\uff0c\u7c7b\u548c\u5bf9\u8c61\u7b49\u3002
\u5b9a\u4e49
namespace A{\nint a = 100;\n}\nnamespace B{\nint b = 200;\n}\nvoid test(){\ncout << A::a << endl;\ncout << B::a << endl;\n}\n
namespace\u53ef\u4ee5\u5d4c\u5957\uff0c\u53ef\u4ee5\u5728namespace\u4e2d\u5b9a\u4e49namespace
namespace A{\nint a = 100;\nnamespace B{\nint a = 2000;\n}\n}\nvoid test(){\ncout << A::a << endl;\ncout << A::B::a << endl;\n}\n
namespace\u662f\u5f00\u653e\u7684\uff0c\u5373\u53ef\u4ee5\u968f\u65f6\u628a\u65b0\u6210\u5458\u52a0\u5165\u5df2\u6709\u7684namespace\u4e2d
namespace A{\nint a = 100;\nint b = 200;\n}\n// \u5c06c\u6dfb\u52a0\u5230\u5df2\u6709\u7684namespace\u4e2d\nnamespace A{\nint c = 300;\n}\nvoid test(){\ncout << A::a << endl;\ncout << A::c << endl;\n}\n
namespace\u53ef\u4ee5\u5b58\u653e\u53d8\u91cf\u548c\u51fd\u6570
namespace A{\nint a = 100;\nvoid func(){\ncout << a << endl;\n}\n}\nvoid test(){\ncout << a << endl;\nA::func();\n}\n
namespace\u4e2d\u7684\u51fd\u6570\u53ef\u4ee5\u5728namespace\u5916\u5b9a\u4e49
namespace A{\nint a = 100;\nvoid func();\n}\n// \u6210\u5458\u51fd\u6570\nvoid A::func(){\ncout << a << endl;\n}\n// \u666e\u901a\u51fd\u6570\nvoid funcb(){\ncout << A::a << endl;\n}\nvoid test(){\nA::func();\nfuncb();\n}\n
\u53d8\u91cf\u540d\u51b2\u7a81\u7684\u89e3\u51b3\u65b9\u6cd5
\u5982\u679c\u5168\u5c40\u53d8\u91cf\u4e0e\u5c40\u90e8\u53d8\u91cf\u51b2\u7a81\uff0c\u90a3\u4e48\u6309\u5c31\u8fd1\u539f\u5219\u6765\u4f7f\u7528\u3002\uff08\uff1f\uff09
"},{"location":"CS/CPP/templates/","title":"\u6a21\u677fTemplate \u548c \u6807\u51c6\u6a21\u677f\u5e93STL","text":"\u9700\u6c42\uff1a\u8ba9\u6211\u4eec\u7684\u4ee3\u7801\u72ec\u7acb\u4e8e\u5177\u4f53\u7684\u7c7b\u578b\u5de5\u4f5c\u3002
\u6211\u4eec\u5199\u51fa\u4e00\u4e2a\u9002\u7528\u4e8e\u6240\u6709\u7c7b\u578b\u7684\u6570\u636e\u7ed3\u6784\u7684\u7c7b\u6216\u7b97\u6cd5\uff08\u51fd\u6570\uff09\uff0c\u5728\u771f\u6b63\u9700\u8981\u4f7f\u7528\u65f6\u751f\u6210\u4e00\u4e2a\u9002\u7528\u4e8e\u6240\u9700\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002\u8fd9\u79cd\u7f16\u7a0b\u8303\u5f0f\u79f0\u4e3a\u8303\u578b\u7f16\u7a0b\u3002
\u6a21\u677f\u7c7b\u7684\u5199\u6cd5
template<typename T>\nclass Container{\nT *data;\nunsigned size, capa;\npiblic:\nContainer(unsigned capa = 512): data(new T[capa]){}\n~Container() {delete[] data;}\nT& operator[](unsigned index) {return data[index];}\n}\n
\u8fd9\u91cctemplate T\u8868\u660e\u5b83\u63a5\u53d7\u4e00\u4e2a\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570\uff0c\u540d\u5b57\u662fT\u3002\u5728\u6a21\u677f\u7684\u5b9a\u4e49\u5185\u90e8\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5230\u8fd9\u4e2a\u7c7b\u578b\u53d8\u91cfT\u3002
\u7279\u5316\uff1a\u6839\u636e\u6a21\u677f\u751f\u6210\u5b9e\u9645\u7684\u7c7b\u7684\u8fc7\u7a0b
Container<int> ci;\nContainer<double> cd;\n
\u6a21\u677f\u51fd\u6570\u8981\u600e\u4e48\u5199
template<typename T>\nT abs(T x) {return x>0?x:-x;}\n
\u6a21\u677f\u8fd0\u7b97\u7b26\u91cd\u8f7d\u600e\u4e48\u5199
template<typename T>\nclass Container {\nT* data;\nunsigned size = 0, capa;\npublic: Container(unsigned capa = 512) : data(new T[capa]), capa(capa){}\n~Container(){delete[] data;}\nT& operator[](unsigned index) {return data[index];}\nconst T& operator[](unsigned idnex) const {return data[index];}\nunsigned getSize() const {return size;}\nunsigned getCapa() const {return capa;}\nContainer &add(T val){\ndata[size++] = val;\nreturn *this;\n}\n};\ntemplate<typename T>\nostream & operator<<(ostream& os, const Container<T>&c){\nfor (unsigned i = 0; i < c.getSize(); i++){\nos << c[i] << ' ';\nreturn os;\n}\n}\n
"},{"location":"CS/CPP/templates/#reference","title":"Reference","text":"7 \u6a21\u677f (I) - \u57fa\u672c\u77e5\u8bc6\u4e0e STL \u4f7f\u7528 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4
"},{"location":"CS/CPP/templates/#template","title":"\u53ef\u53d8\u53c2\u6570\u6a21\u677f templateC++11\u7684\u65b0\u7279\u6027 \u5bf9\u53c2\u6570\u9ad8\u5ea6\u6cdb\u5316\uff0c\u53ef\u4ee5\u8868\u793a0\u5230\u4efb\u610f\u4e2a\u4efb\u610f\u7c7b\u578b\u7684\u53c2\u6570\u3002
\u8bed\u6cd5
template <class ...T> // \u58f0\u660e\u4e00\u4e2a\u53c2\u6570\u5305\uff0c\u8fd9\u4e2a\u53c2\u6570\u5305\u4e2d\u5305\u542b0\u5230\u4efb\u610f\u4e00\u4e2a\u53c2\u6570\u6a21\u677f\nvoid f(T... args); // \u5728\u6a21\u677f\u5b9a\u4e49\u7684\u53f3\u8fb9\uff0c\u53ef\u4ee5\u5c06\u53c2\u6570\u5305\u5c55\u5f00\u6210\u4e00\u4e2a\u4e00\u4e2a\u72ec\u7acb\u53c2\u6570\n
\u6700\u5927\u7684\u96be\u70b9\uff1a\u5982\u4f55\u5c55\u5f00\u53ef\u53d8\u6a21\u677f\u53c2\u6570
\u6253\u5370\u53c2\u6570\u4e2a\u6570\uff1a
template<class ...T>\nvoid f(T... args)\n{\n cout << sizeof...(args) << endl;\n}\n\nf();\nf(1, 2);\nf(1, 2.5, \"\");\n
\u9012\u5f52\u65b9\u5f0f\u5c55\u5f00\u53c2\u6570\u5305
#include <iostream>\nusing namespace std;\n\n// \u9012\u5f52\u7ec8\u6b62\u51fd\u6570\nvoid print(){\n cout << \"empty\" << endl;\n}\n\n// \u5c55\u5f00\u51fd\u6570\ntemplate<class T, class ...Args>\nvoid print(T head, Args... rest){\n cout << \"parameter\" << head << endl;\n print(rest...);\n}\n\nint main(){\n print(1, 2, 3, 4);\n return 0;\n}\n
\u4e0a\u8ff0\u4f8b\u5b50\u4f1a\u8f93\u51fa\u6bcf\u4e00\u4e2a\u53c2\u6570\uff0c\u76f4\u5230\u7a7a\u65f6\u8f93\u51faempty\u3002\u5c55\u5f00\u53c2\u6570\u5305\u7684\u51fd\u6570\u6709\u4e24\u4e2a\uff0c\u4e00\u4e2a\u662f\u9012\u5f52\u51fd\u6570\uff0c\u53e6\u4e00\u4e2a\u662f\u9012\u5f52\u7ec8\u6b62\u51fd\u6570\uff0c\u53c2\u6570\u5305Args\u2026\u5728\u5c55\u5f00\u7684\u8fc7\u7a0b\u4e2d\u9012\u5f52\u8c03\u7528\u81ea\u5df1\uff0c\u6bcf\u8c03\u7528\u4e00\u6b21\uff0c\u53c2\u6570\u5305\u4e2d\u7684\u53c2\u6570\u5c31\u5c11\u4e00\u4e2a\uff0c\u76f4\u5230\u6240\u6709\u53c2\u6570\u90fd\u5c55\u5f00\u4e3a\u6b62\u3002\u5f53\u6ca1\u6709\u53c2\u6570\u65f6\uff0c\u5219\u8c03\u7528\u975e\u6a21\u677f\u51fd\u6570print()\u7ec8\u6b62\u9012\u5f52\u8fc7\u7a0b\u3002
\u7ec8\u6b62\u51fd\u6570\u4e5f\u53ef\u4ee5\u5199\u6210
template<class T>\nvoid print(T t){\n cout << t << endl;\n}\n
\u53ef\u53d8\u6a21\u677f\u53c2\u6570\u6c42\u548c
template<typename T>\nT sum(T t){\n return t;\n}\ntemplate<typename T, typename ... Types>\nT sum(T first, Types ...rest){\n return first + sum<T> (rest...);\n}\n\nsum(1, 2, 3, 4);\n
\u9012\u5f52\u51fd\u6570\u5c55\u5f00\u53c2\u6570\u5305\u662f\u4e00\u79cd\u6807\u51c6\u505a\u6cd5\uff0c\u4e5f\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u4f46\u662f\u7f3a\u70b9\u65f6\u5fc5\u987b\u8981\u4e00\u4e2a\u91cd\u8f7d\u7684\uff08\u540c\u540d\uff09\u9012\u5f52\u7ec8\u6b62\u51fd\u6570\u6765\u7ec8\u6b62\u9012\u5f52\u3002
\u6216\u8005\u4e0d\u9012\u5f52\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u501f\u52a9\u9017\u53f7\u8868\u8fbe\u5f0f\u548c\u521d\u59cb\u5316\u5217\u8868\u3002\u524d\u9762\u7684print\u53ef\u4ee5\u8fd9\u4e48\u5199
template<class T>\nvoid printarg(T t){\n cout << t << endl;\n}\n\ntemplate <class ...Args>\nvoid expand(Args... args){\n int arr[] = {(printarg(args), 0)...};\n}\n\nexpand(1, 2, 3, 4);\n
arr\u8fd9\u4e2a\u6570\u7ec4\u7684\u76ee\u7684\u5355\u7eaf\u662f\u5c55\u5f00\u53c2\u6570\u5305
\u5982\u679c\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u652f\u6301lambda\u8868\u8fbe\u5f0f
template<class F, class... Args> void expand(const F& f, Args&&...args){\ninitializer_list<int>{(f(std::forward< Args>(args)), 0)};\n}\nexpand([](int i){cout << i << endl;}, 1,2,3);\n
\u53ef\u4ee5\u5e26\u4efb\u610f\u4e2a\u6570\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u6bd4\u5982std::tuple
template<class... Types>\nclass tuple;\n
\u6a21\u677f\u504f\u7279\u5316\u548c\u9012\u5f52\u65b9\u5f0f\u5c55\u5f00\u53c2\u6570\u5305
\u53ef\u53d8\u53c2\u6570\u6a21\u677f\u7c7b\u7684\u5c55\u5f00\u4e00\u822c\u9700\u8981\u5b9a\u4e49\u4e24\u5230\u4e09\u4e2a\u7c7b\uff0c\u5305\u62ec\u7c7b\u58f0\u660e\u548c\u504f\u7279\u5316\u7684\u6a21\u677f\u7c7b
// \u524d\u5411\u58f0\u660e\ntemplate<typename... Args>\nstruct Sum;\n\n// \u57fa\u672c\u5b9a\u4e49\ntemplate<typename First, typename... Rest>\nstruct Sum<First, Rest...>{\n enum { value = Sum<First>::value + Sum<Rest...>::value };\n}\n\n// \u9012\u5f52\u7ec8\u6b62\ntemplate<typename Last>\nstruct Sum<Last>{\n enum { value = sizeof(Last) };\n}\n
","text":""},{"location":"CS/CPP/templates/#stl","title":"\u6807\u51c6\u6a21\u677f\u5e93 STL STL\u516d\u5927\u90e8\u4ef6\uff1a\u5bb9\u5668\uff08containers\uff09\uff0c\u5206\u914d\u5668\uff08allocators\uff09\uff0c\u7b97\u6cd5\uff08algorithm\uff09\uff0c\u8fed\u4ee3\u5668\uff08iterator\uff09\uff0c\u9002\u914d\u5668\uff08adapters\uff09\uff0c\u4eff\u51fd\u6570\uff08functors\uff09
","text":""},{"location":"CS/CPP/templates/#_1","title":"\u5e38\u7528\u7684\u5bb9\u5668","text":"vector, deque, list, set/multiset, map/multimap \u7b49
"},{"location":"CS/CPP/templates/#1-vector","title":"1. Vector","text":"Vector\u662f\u4e00\u79cd\u53d8\u957f\u6570\u7ec4\u3002
#include<vector>\nusing namespace std;\nvector<int> name;\nvector<double> name;\nvector<char> name;\nvector<struct node> name;\n// \u8fd9\u4e24\u4e2a\u4e3b\u8981\u6709\u901f\u5ea6\u4e0a\u7684\u533a\u522b\uff0carray\u975e\u5e38\u6162\uff0cvector\u5feb\u4e00\u4e9b\nvector< vector<int> > name; // > >\u4e4b\u95f4\u8981\u52a0\u7a7a\u683c\uff0c\u65b0\u6807\u51c6\u4e0d\u7528\u52a0\u4e86\nvector<int> array[SIZE]; // \u8fd9\u4e2a\u4e0d\u662f\u5f88\u5e38\u7528\uff0c\u56e0\u4e3a\u5bb9\u6613\u51fa\u9519\uff0c\u4e14\u6570\u7ec4\u4e0d\u77e5\u9053\u81ea\u5df1\u7684\u957f\u5ea6\uff0c\u8fd8\u6709std::array\n
\u8bbf\u95ee\u65b9\u5f0f
// 1. \u901a\u8fc7\u4e0b\u6807\n#include<iostream>\n#include<vector>\nusing namespace std;\nint main()\n{\nvector<int> vi;\nvi.push_back(1);\ncout<<vi[0]<<endl;\nreturn 0;\n}\n// 2. \u901a\u8fc7\u8fed\u4ee3\u5668\nvector<int>::iterator\nvector<double>::iterator\n// \u4f8b\n#include<iostream>\n#include<vector>\nint main()\n{\nvector<int> v;\nfor(int i = 0; i < 5; i++)\n{\nv.push_back(i); }\nvector<int>::iterator it=v.begin();\nfor(int i = 0; i < v.size(); i++)\n{\ncout << it[i] << \" \";\n// \u4e5f\u53ef\u4ee5\u5199\u6210 cout << * (it + i) << \" \";\n}\nreturn 0;\n}\n// \u6216\u8005\u4f18\u96c5\u7684\u5199\u6cd5\n// \u56e0\u4e3a\u8fed\u4ee3\u5668\u4e0d\u652f\u6301 it < v.end()\u7684\u5199\u6cd5\uff0c\u53ea\u80fd\u5199!=\nfor (vector<int>::iterator it=v.begin(); it!=v.end();it++)\n{\ncout << *it << \" \";\n}\n
\u5e38\u7528\u51fd\u6570 push_back(item) // \u5728vector\u540e\u9762\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\npop_back(item) // \u5728vector\u540e\u9762\u5220\u9664\u4e00\u4e2a\u5143\u7d20\nsize(vector) // \u8fd4\u56de\u5143\u7d20\u4e2a\u6570\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(1)\nclear(vector) // \u6e05\u9664\u6240\u6709\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(N)\ninsert(position, x) // \u5728position\u7684\u5730\u65b9\u63d2\u5165\u4e00\u4e2ax\n// \u4f8b\nv.insert(v.begin()+2, -1); // \u76f8\u5f53\u4e8e\u5728v[2]\u5904\u63d2\u5165\u4e00\u4e2a-1\nerase(position);\nerase(positionBegin, positionEnd); // \u5de6\u95ed\u53f3\u5f00\n
"},{"location":"CS/CPP/templates/#2-set","title":"2. set","text":"\u96c6\u5408\u662f\u4e0d\u5141\u8bb8\u5143\u7d20\u91cd\u590d\u7684\u65e0\u5e8f\u5bb9\u5668
#include<set>\nusing namespace std;\nset<int> name;\nset<double> name;\nset<char> name;\nset<struct node> name;\nset<set<int> > name;\n
\u56e0\u4e3a\u65e0\u5e8f\uff0cset\u53ea\u80fd\u901a\u8fc7iterator\u8bbf\u95ee\uff0c\u9664\u4e86vector\u548cstring\u4e4b\u5916\u7684\u5bb9\u5668\u90fd\u4e0d\u80fd\u901a\u8fc7\u4e0b\u6807\u8bbf\u95ee set<int>::iterator it;\nset<char>::iterator it;\n
\u5e38\u7528\u51fd\u6570 st.insert(X);\nst.find(X); // \u8fd4\u56deset\u4e2dvalue\u6240\u5bf9\u5e94\u7684\u8fed\u4ee3\u5668\uff0c\u4e5f\u5c31\u662fvalue\u7684\u6307\u9488\n// \u4f8b\nset<int>::iterator it = st.find(2);\ncout << *it << endl;\n// \u53ef\u4ee5\u76f4\u63a5\u5199\u6210\ncout << *(st.find(2)) << endl;\nst.erase(it); // \u5220\u9664\u67d0\u4e2a\u5730\u5740\u7684\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(1)\nst.erase(X); // \u5220\u9664\u67d0\u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(N)\nst.erase(itBegin, itEnd);\nst.size();\n
"},{"location":"CS/CPP/templates/#3-deque","title":"3. deque","text":"deque\u662f\u7531\u4e00\u6bb5\u5b9a\u91cf\u8fde\u7eed\u7a7a\u95f4\u6784\u6210\uff0c\u4e00\u65e6\u8981\u5728deque\u7684\u524d\u7aef\u548c\u5c3e\u7aef\u589e\u52a0\u7a7a\u95f4\uff0c\u4fbf\u914d\u7f6e\u4e00\u6bb5\u8fde\u7eed\u7a7a\u95f4\uff0c\u4e32\u5728\u6574\u4e2adeque\u7684\u5934\u90e8\u548c\u5c3e\u90e8.
"},{"location":"CS/CPP/templates/#4-list","title":"4. list","text":""},{"location":"CS/CPP/templates/#5-mapunordered_map","title":"5. map/unordered_map","text":""},{"location":"CS/CPP/templates/#6-string","title":"6. string","text":"// init\n#include<string>\nstring str;\nstring str = \"Hello\";\ncin >> str;\ncout << str;\n// assignment\nchar cstr1[20];\nchar cstr2[20] = \"jaguar\";\nstring str1;\nstring str2 = \"panther\";\ncstr1 = cstr2; // illegal\nstr1 = str2; // legal\n// concatenation\nstring str3;\nstr3 = str1 + str2;\nstr1 += str2;\nstr1 += \"a string literal\";\n// constructors (Ctors)\nstring (const char *cp, int len);\nstring (const string& s2, int pos);\nstring (const string& s2, int pos, int len);\n// sub-string\nsubstr (int pos, int len);\n// modification\nassign (...);\ninsert (...);\ninsert (int pos, const string& s);\nerase (...);\nappend (...);\nreplace (...);\nreplace (int pos, int len, const string& s);\n...\n// search\nfind (const string& s);\n// File I/O\n#include <ifstream> // read from file\n#include <ofstream> // write to file\n// write into file\nofstream File1(\"...\");\nFile1 << \"Hello world\" << std::enl;\n// read from file\nifstream File2(\"...\");\nstd::string str;\nFile2 >> str;\n
"},{"location":"CS/CPP/templates/#_2","title":"\u7b97\u6cd5","text":"\u7b97\u6cd5\u90e8\u5206\u4e3b\u8981\u7531<algorithm> <numeric> <functional>
\u7ec4\u6210 <algorithm>
\u662f\u6700\u5927\u7684\u4e00\u4e2a <numeric>
\u4f53\u79ef\u5f88\u5c0f\uff0c\u53ea\u5305\u62ec\u51e0\u4e2a\u5728\u5e8f\u5217\u4e0a\u8fdb\u884c\u7b80\u5355\u6570\u5b66\u8fd0\u7b97\u7684\u6a21\u677f\u51fd\u6570 <functional>
\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6a21\u677f\u7c7b\uff0c\u7528\u4ee5\u58f0\u660e\u51fd\u6570\u5bf9\u8c61
\u7528\u8fed\u4ee3\u5668\u53ef\u4ee5\u8bfb\u53d6\u5b83\u6307\u5411\u7684\u5143\u7d20\u3002\u8fed\u4ee3\u5668\u540d\u5c31\u8868\u793a\u8fed\u4ee3\u5668\u6307\u5411\u7684\u5143\u7d20\uff0c\u901a\u8fc7\u975e\u5e38\u91cf\u8fed\u4ee3\u5668\u8fd8\u80fd\u4fee\u6539\u5176\u6307\u5411\u7684\u5143\u7d20\u3002
#include<iostream> #include<vector> using namespace std; int main() { vector<int> v; for (int n = 0; n < 5; ++n) v.push_back(n); vector<int>::iterator i; for (i = v.begin(); i != v.end(); i++) { cout << *i << \" \"; // *i \u662f i \u6307\u5411\u7684\u5143\u7d20 *i *= 2; \n} }\n
"},{"location":"CS/CPP/templates/#stl_1","title":"\u7c7b\u5e93\u548cSTL STL\u662f\u8303\u578b\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u4e00\u4e2a\u8303\u4f8b\uff0c\u542b\uff1a\u5bb9\u5668\uff08container\uff09\u3001\u8fed\u4ee3\u5668\uff08iterator\uff09\u3001\u7b97\u6cd5\uff08algorithm\uff09\u3001\u51fd\u6570\u5bf9\u8c61\uff08function object\uff09\u3002\u7c7b\u5e93\u662f\u7c7b\u7684\u96c6\u5408\uff0c\u662f\u4e00\u79cd\u9884\u5b9a\u4e49\u7684\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u5e93\u3002
","text":""},{"location":"CS/CPP/templates/#c","title":"C++\u7684\u6807\u51c6\u5e93","text":"using namespace std;
\u5bb9\u5668\uff08container\uff09\u7c7b\u662f\u7528\u6765\u5bb9\u7eb3\u3001\u5305\u542b\u4e00\u7ec4\u5143\u7d20\u6216\u5143\u7d20\u96c6\u5408\u7684\u5bf9\u8c61\u7684\u3002STL\u4e2d\u5b9a\u4e49\u4e86\u591a\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u5bb9\u5668\uff0c\u4f8b\u5982
\u5b9a\u4e49
vector<int> iv;\nvector<int> cv(5);\nvector<int> cv(5, 'x');\nvector<int> iv2(iv);\n
\u4f7f\u7528
#include<iostream>\n#include<vector>\nusing namespace std;\nint main()\n{\nvector<char> v; // create zero-len vector\nint i;\n// put values into a vector\nfor (i = 0; i < 10; i++)\nv.push_back('A' + i);\n// can access vector contents using subsripting\nfor (i = 0; i < 10; i++)\ncout << v[i] << \" \";\ncout << endl;\n// access via iterator\nvector<char>::iterator p = v.begin();\nwhile(p != v.end())\n{\ncout << *p << \" \";\np++;\n}\nreturn 0;\n}\n
"},{"location":"CS/CPP/templates/#list","title":"\u7ebf\u6027\u8868 list","text":"\u5b9a\u4e49\u4e86\u53cc\u5411\u7684\u7ebf\u6027\u8868\uff0c\u53c8\u53ef\u79f0\u4e3a\u53cc\u5411\u94fe\u8868\u3002list\u7c7b\u53ea\u652f\u6301\u987a\u5e8f\u8bbf\u95ee\u3002
// sort a list\n#include<iostream>\n#include<list>\n#include<cstdlib>\nusing namespace std;\nint main()\n{\nint i;\nlist<char> lst;\n// create a list of random characters\nfor (i = 0; i < 10; i++)\nlist.push_back('A' + (rand()%26));\n}\n
"},{"location":"CS/CPP/templates/#set","title":"\u96c6\u5408 set","text":"#include<set>\n#include<iostream>\n#include<string>\nint main()\n{\nstd::set<std::string> source;\nstd::string input;\nfor(int i=0;i<6;i++)\n{\nstd::cin>>input;\nsource.insert(input);\n}\nstd::set<std::string>::iterator at = source.begin();\nwhile(at != source.end())\nstd::cour << * at++ << std::endl;\n}\n
"},{"location":"CS/CPP/templates/#multiset","title":"multiset","text":""},{"location":"CS/CPP/templates/#map","title":"\u6620\u5c04 map","text":""},{"location":"CS/CPP/templates/#queue","title":"\u961f\u5217 queue","text":""},{"location":"CS/CPP/templates/#stdstack","title":"std::stack","text":""},{"location":"CS/CPP/templates/#stdpair","title":"std::pair","text":""},{"location":"CS/CPP/templates/#string","title":"\u5b57\u7b26\u4e32string","text":""},{"location":"CS/CPP/templates/#_3","title":"\u7b97\u6cd5\u5e93 ` #include<algorithm>\n#include<iostream>\n#include<string>\n#include<vector>\nusing namespace std;\nvoid load(vector<string>&);\nvoid print(vector<string>);\nconst int SIZE = 8;\nint main()\n{\nvector<string> v(SIZE);\nload(v);\nsort(v.begin(), v.end()); // \u6307\u5b9a\u6392\u5e8f\u7684\u8d77\u6b62\u4f4d\u7f6e\nprint(v);\nreturn 0;\n}\n// \u4f1a\u6309\u7167\u5b57\u6bcd\u5e8f\u6392\u5e8f\n
"},{"location":"CS/CPP/templates/#_4","title":"\u8fed\u4ee3\u5668 \u662f\u4e00\u79cd\u7c7b\u4f3c\u6307\u9488\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u5668\u6765\u8bbf\u95ee\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u3002
#include<list>\n#include<iostream>\nint main()\n{\nusing namespace std;\nlist<int> c1;\nlist<int>::iterator c1_Iter;\nlist<int>::reverse_iterator c1_rIter;\nc1_rIter = c1.rbegin(); // the last element\n}\n
"},{"location":"CS/CPP/templates/#_5","title":"\u53c2\u8003\u8d44\u6599 https://zhuanlan.zhihu.com/p/344558356 LJJ PPT
","text":""},{"location":"CS/CPP/type/","title":"\u7c7b\u578b\u548c\u7c7b\u578b\u8f6c\u6362 Type & Type Conversion","text":""},{"location":"CS/CPP/type/#type-info","title":"Type info \u5e93","text":"#include <typeinfo>\n
\u7b80\u4ecb - \u548csizeof\u8fd9\u7c7b\u64cd\u4f5c\u7b26\u4e00\u6837\uff0ctypeid\u662fc++\u7684\u5173\u952e\u5b57\u4e4b\u4e00 - typeid\u64cd\u4f5c\u7b26\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u540d\u4e3atype_info\u7684\u6807\u51c6\u5e93\u7c7b\u578b\u7684\u5bf9\u8c61\u7684\u5f15\u7528\uff08\u5728\u5934\u6587\u4ef6typeinfo\u4e2d\u5b9a\u4e49\uff09 - c++\u5e76\u6ca1\u6709\u89c4\u5b9atypeid\u5b9e\u73b0\u6807\u51c6\uff0c\u5404\u4e2a\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u4e0d\u4e00\u6837 - \u7f16\u8bd1\u5668\u4f1a\u4e3a\u6bcf\u4e00\u79cdtypeid\u64cd\u4f5c\u7684\u7c7b\u578b\u751f\u6210\u4e00\u4efd\u4fdd\u5b58\u5728\u6570\u636e\u6bb5\u7684type_info\u6570\u636e - \u6bcf\u79cd\u7c7b\u578b\u7684type_info\u6570\u636e\u957f\u5ea6\u4f9d\u8d56\u4e8e\u7c7b\u578b\u540d\u79f0\uff0c\u81f3\u5c119\u4e2a\u5b57\u8282
\u7528\u6cd5 - \\== \u548c!=\u64cd\u4f5c
#include <iostream>\n#include <typeinfo>\nstruct Base{};\nstruct Derived: Base {};\nstruct Poly_Base {virtual void Member(){}};\nstruct Poly_Derived: Poly_Base {};\ntypedef int my_int_type;\nint main()\n{\nstd::cout << std::boolalpha;\nstd::cout << \"int vs my_int_type: \";\nstd::cout << (typeid(int) == typeid(my_int_type)) << '\\\\n';\nstd::cout << \"Base vs Derived: \";\nstd::cout << (typeid(Base) == typeid(Derived)) << '\\\\n'; // \u8f93\u51fafalse\nBase* pbase = new Derived;\n}\n
#include <iostream>\n#include <typeinfo>\nstruct Base{}\nstruct Derived: Base{};\ntemplate <class T>\nvoid swap(T a, T b){\nstd::cout << \"T is: \" << typeid(T).name() << '\\\\n';\nT temp = a;\na = b;\nb = temp;\n}\nint main(){\nint i;\nint* ptr;\nstd::cout << \"int is: \" << typeid(int).name() << '\\\\n';\nstd::cout << \" i is: \" << typeid(i).name() << '\\\\n';\n}\n
\u53c2\u8003 C++\u4e2d\u7684typeInfo\u7528\u6cd5\u603b\u7ed3_\u975e\u665a\u975e\u665a\u7684\u535a\u5ba2-CSDN\u535a\u5ba2
"},{"location":"CS/CPP/type/#_1","title":"\u7c7b\u578b\u8f6c\u6362","text":""},{"location":"CS/CPP/type/#const_cast","title":"const_cast","text":"const_cast<new_type>(expression);\n
#include <iostream>\nstruct type\n{\nint i;\ntype(): i(3) {}\nvoid f(int v) const\n{\n// this->i = v; // compile error: this is a pointer to const\nconst_cast<type*>(this)->i = v; // OK as long as the type object isn't const\n}\n};\nint main()\n{\nint i = 3; // i is not declared const\nconst int& rci = i;\nconst_cast<int&>(rci) = 4; // OK: modifies i\nstd::cout << \"i = \" << i << '\\\\n';\ntype t; // if this was const type t, then t.f(4) would be undefined behavior\nt.f(4);\nstd::cout << \"type::i = \" << t.i << '\\\\n';\nconst int j = 3; // j is declared const\n[[maybe_unused]]\nint* pj = const_cast<int*>(&j);\n// *pj = 4; // undefined behavior\n[[maybe_unused]]\nvoid (type::* pmf)(int) const = &type::f; // pointer to member function\n// const_cast<void(type::*)(int)>(pmf); // compile error: const_cast does\n// not work on function pointers\n}\n
"},{"location":"CS/CPP/type/#dynamic_cast","title":"dynamic_cast","text":"dynamic_cast<new_type>(expression);\n
#include <iostream>\nstruct V\n{\nvirtual void f() {} // must be polymorphic to use runtime-checked dynamic_cast\n};\nstruct A : virtual V {};\nstruct B : virtual V\n{\nB(V* v, A* a)\n{\n// casts during construction (see the call in the constructor of D below)\ndynamic_cast<B*>(v); // well-defined: v of type V*, V base of B, results in B*\ndynamic_cast<B*>(a); // undefined behavior: a has type A*, A not a base of B\n}\n};\nstruct D : A, B\n{\nD() : B(static_cast<A*>(this), this) {}\n};\nstruct Base\n{\nvirtual ~Base() {}\n};\nstruct Derived: Base\n{\nvirtual void name() {}\n};\nint main()\n{\nD d; // the most derived object\nA& a = d; // upcast, dynamic_cast may be used, but unnecessary\n[[maybe_unused]]\nD& new_d = dynamic_cast<D&>(a); // downcast\n[[maybe_unused]]\nB& new_b = dynamic_cast<B&>(a); // sidecast\nBase* b1 = new Base;\nif (Derived* d = dynamic_cast<Derived*>(b1); d != nullptr)\n{\nstd::cout << \"downcast from b1 to d successful\\\\n\";\nd->name(); // safe to call\n}\nBase* b2 = new Derived;\nif (Derived* d = dynamic_cast<Derived*>(b2); d != nullptr)\n{\nstd::cout << \"downcast from b2 to d successful\\\\n\";\nd->name(); // safe to call\n}\ndelete b1;\ndelete b2;\n}\n
"},{"location":"CS/CPP/type/#reinterpret_cast","title":"reinterpret_cast","text":"reinterpret_cast<new_type>(expression)\n
#include <cassert>\n#include <cstdint>\n#include <iostream>\nint f() { return 42; }\nint main()\n{\nint i = 7;\n// pointer to integer and back\nstd::uintptr_t v1 = reinterpret_cast<std::uintptr_t>(&i); // static_cast is an error\nstd::cout << \"The value of &i is \" << std::showbase << std::hex << v1 << '\\\\n';\nint* p1 = reinterpret_cast<int*>(v1);\nassert(p1 == &i);\n// pointer to function to another and back\nvoid(*fp1)() = reinterpret_cast<void(*)()>(f);\n// fp1(); undefined behavior\nint(*fp2)() = reinterpret_cast<int(*)()>(fp1);\nstd::cout << std::dec << fp2() << '\\\\n'; // safe\n// type aliasing through pointer\nchar* p2 = reinterpret_cast<char*>(&i);\nstd::cout << (p2[0] == '\\\\x7' ? \"This system is little-endian\\\\n\"\n: \"This system is big-endian\\\\n\");\n// type aliasing through reference\nreinterpret_cast<unsigned int&>(i) = 42;\nstd::cout << i << '\\\\n';\n[[maybe_unused]] const int &const_iref = i;\n// int &iref = reinterpret_cast<int&>(\n// const_iref); // compiler error - can't get rid of const\n// Must use const_cast instead: int &iref = const_cast<int&>(const_iref);\n}\n
"},{"location":"CS/CPP/type/#static_cast","title":"static_cast","text":"static_cast<new_type>(expression)\n
struct B {}; struct D : B { B b; }; D d; B& br1 = d; B& br2 = d.b; static_cast<D&>(br1); // OK: lvalue denoting the original d object \nstatic_cast<D&>(br2); // UB: the b subobject is not a base class subobject\n
ZJU OS\u64cd\u4f5c\u7cfb\u7edf\u8bfe\u7a0b\u7b14\u8bb0\u3002
\u4f9b\u81ea\u5b66\u800c\u5199\u7684\uff0c\u4e0d\u4fdd\u8bc1\u5199\u5f97\u6613\u61c2\u3002\u56e0\u6b64\u4e0d\u5efa\u8bae\u9605\u8bfb\uff01
\u63a8\u8350\u53c2\u8003\u8d44\u6599
\u3010\u7b14\u8bb0\u3011RISC-V ISA - \u9e64\u7fd4\u4e07\u91cc\u7684\u7b14\u8bb0\u672c (tonycrane.cc)
\u3010\u7b14\u8bb0\u3011Unit 4: \u5b58\u50a8\u7ba1\u7406 | Storage Management [\u672a\u5b8c\u6210] - Isshiki\u4fee's Notebook (isshikih.top)
\u3010\u7b14\u8bb0\u30111 \u5199\u5728\u524d\u9762 - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io)
\u3010\u4e60\u9898\u3011rCore-Tutorial-Book-v3 3.6.0-alpha.1 \u6587\u6863 (rcore-os.cn)
\u3010\u6587\u6863\u3011RISC-V\u624b\u518c (riscvbook.com)
\u3010\u6587\u6863\u3011makefile\u4ecb\u7ecd \u2014 \u8ddf\u6211\u4e00\u8d77\u5199Makefile 1.0 \u6587\u6863 (seisman.github.io)
\u3010\u6587\u6863\u3011riscv-asm-manual/riscv-asm.md at master \u00b7 riscv-non-isa/riscv-asm-manual (github.com)
"},{"location":"CS/OS/mem_file/","title":"OS Lecture \u5185\u5b58\u548c\u6587\u4ef6\u7cfb\u7edf","text":""},{"location":"CS/OS/mem_file/#8","title":"8. \u4e3b\u5b58","text":"\u5e38\u8bc6\uff1a
\u5185\u5b58\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u5b57\u8282\u6570\u7ec4\uff0cCPU\u6839\u636ePC(Program Counter)\u7684\u503c\u4ece\u5185\u5b58\u4e2d\u63d0\u53d6\u6307\u4ee4\u3002\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b\u8fd0\u884c\u7684\u524d\u63d0\u662f\uff0c\u7a0b\u5e8f\u4ee3\u7801\u548c\u9700\u8981\u8bbf\u95ee\u7684\u6570\u636e\u5728\u5185\u5b58\u4e2d\u3002
CPU\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7684\u901a\u7528\u5b58\u50a8\u53ea\u6709main memory\u548cregisters\u3002\u5bf9registers\u7684\u8bbf\u95ee\u901a\u5e38\u53ef\u4ee5\u5728\u4e00\u4e2aCPU\u65f6\u949f\u5468\u671f\u5b8c\u6210\uff0c\u4f46\u662f\u8bbf\u95ee\u5185\u5b58\u9700\u8981\u591a\u4e2a\u65f6\u949f\u5468\u671f\uff0c\u8fd9\u5c31\u4f1a\u5f15\u8d77\u6307\u4ee4\u7684stall\u3002\u56e0\u4e3a\u6211\u4eec\u4e0d\u60f3\u8981stall\uff0c\u6240\u4ee5\u6211\u4eec\u5728CPU\u4e0a\u8bbe\u8ba1\u4e86\u5b58\u53d6\u66f4\u5feb\u7684\u5185\u5b58cache\u3002
\u8868\u793a\u6e90\u7a0b\u5e8f\u5730\u5740\u7684\u65b9\u6cd5\uff1aAddress Binding
\u6e90\u7a0b\u5e8f\u4e2d\u7684\u5730\u5740\u901a\u5e38\u662f\u7528\u7b26\u53f7\uff08symbolic\uff0c\u4f8b\u5982\u5404\u79cd\u53d8\u91cf\u3001\u51fd\u6570\u540d\u3001\u6c47\u7f16\u4e2d\u7684label\u7b49\uff09\u8868\u793a\u3002\u7f16\u8bd1\u5668\u4f1a\u5c06\u7b26\u53f7\u7ed1\u5230relocatable addresses\uff08\u6bb5\u540d+\u504f\u79fb\u91cf\uff09\u3002\u94fe\u63a5\u5668\u6216\u52a0\u8f7d\u5668\uff08linker/loader\uff09\u4f1a\u5c06relocatable addresses\u7ed1\u5b9a\u5230absolute addresses\u3002\u5f53\u7136\uff0c\u5982\u679c\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u65f6\u5c31\u77e5\u9053\u7a0b\u5e8f\u6240\u5904\u7684\u5185\u5b58\u5730\u5740\uff0c\u5219\u4f1a\u751f\u6210absolute code\u3002
"},{"location":"CS/OS/mem_file/#81-partitioning-strategies","title":"8.1 Partitioning Strategies","text":"\u5728Batch\u7cfb\u7edf\u4e2d\uff0c\u6bcf\u6b21\u53ea\u6709\u4e00\u4e2a\u7a0b\u5e8f\u88ab\u52a0\u8f7d\u5165\u7269\u7406\u5185\u5b58\uff0c\u5e76\u8fd0\u884c\u81f3\u7ed3\u675f\u3002\u5982\u679c\u7a0b\u5e8f\u9700\u8981\u7684\u5b58\u50a8\u7a7a\u95f4\u6bd4\u5185\u5b58\u5927\uff0c\u5219\u5c06\u7a0b\u5e8f\u4e00\u5757\u4e00\u5757\u5207\u5f00
\u4e0eprehistory\u4e0d\u540c\u7684\u662f\uff0c\u73b0\u5728\u9700\u8981\u628a\u591a\u4e2a\u8fdb\u7a0b\u540c\u65f6\u653e\u5165\uff0c\u5e76\u4e14\u652f\u6301\u5feb\u901f\u5207\u6362\u3002\u6700\u7b80\u5355\u7684\u5185\u5b58\u5206\u914d\u65b9\u6cd5\u662f\u5c06\u5185\u5b58\u5207\u6210partition\uff0c\u6bcf\u4e00\u4e2a\u5305\u542b\u4e00\u5757\u8fdb\u7a0b\u3002\u5207\u5206\u7684\u8981\u6c42\u6709
\u5982\u679c\u8fdb\u7a0b\u8bf7\u6c42\u7a7a\u95f4\u6765\u8fd0\u884c\uff0c\u4f46\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\uff0c\u53ef\u4ee5
Fixed Partition\uff1a\u56fa\u5b9apartition\u7684\u5927\u5c0f\u3002\u4f46\u662f\u53ef\u80fd\u9020\u6210\u6d6a\u8d39
Variable Partition\uff1a\u4e0d\u56fa\u5b9apartition\u7684\u5927\u5c0f\u3002OS\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u8868\u8bb0\u5f55\u53ef\u7528\u548c\u5df2\u7528\u7684\u5185\u5b58\u3002\u5b83\u7684\u7f3a\u70b9\u662f\uff1a\u6700\u5f00\u59cb\u5185\u5b58\u662f\u6574\u4e00\u4e2a\u5f88\u5927\u7684\u5185\u5b58\uff08hole\uff09\uff0c\u7ecf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u8fd0\u884c\u540e\uff0c\u51fa\u73b0\u4e00\u7cfb\u5217\u5927\u5c0f\u4e0d\u7b49\u7684\u5b54\uff0c\u8fd9\u4e9b\u5c0f\u7684\u5b54\u90fd\u4e0d\u80fd\u88ab\u5229\u7528\u3002\u79f0\u4e3aexternal fragmentation\u3002
Dynamic Storage-Allocation Problem\uff1a\u6839\u636e\u4e00\u7ec4hole\u6765\u5206\u914d\u5927\u5c0f\u4e3an\u7684\u8bf7\u6c42\uff0c\u79f0\u4e3adynamic storage-allocation problem.
worst-fit\u5bf9\u4e2d\u5c0f\u8fdb\u7a0b\u8f83\u591a\u7684\u60c5\u51b5\u6709\u7528\uff0c\u56e0\u4e3a\u4f7f\u5f97\u5269\u4e0b\u7684\u7a7a\u95f2\u5757\u6bd4\u8f83\u5927\u3002\u4f46\u662f\u5e73\u5747\u60c5\u51b5\u4e0bfirst-fit\u548cbest-fit\u66f4\u597d\u4e00\u70b9\uff0c\u5176\u4e2dfirst-fit\u66f4\u5feb\uff0c\u5176\u5b83\u6ca1\u6709\u4e0ebest-fit\u6709\u660e\u663e\u5dee\u522b\u3002
Protection
\u4fdd\u8bc1\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u4f7f\u7528\u81ea\u5df1\u7684\u5185\u5b58\uff1a\u4f7f\u7528\u4e24\u4e2a\u5bc4\u5b58\u5668\uff0c\u4e00\u4e2abase\uff0c\u4e00\u4e2alimit\uff0c\u5206\u522b\u8868\u793a\u57fa\u5740\u548c\u504f\u79fb\u91cf\u3002\u5f53context switch\u5230\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b or user mode\u60f3\u8981\u8fdb\u884c\u5185\u5b58\u8bbf\u95ee\uff0cCPU\u5c31\u4f1aload\u8fd9\u4e24\u4e2a\u5bc4\u5b58\u5668\u7684\u503c\u3002\u5982\u679c\u975e\u6cd5\u4e86\uff0c\u5c31trap\u6389\uff08\u901a\u5e38\u662fterminate\u8be5\u8fdb\u7a0b\uff09\u3002
\u89e3\u51b3external fragmentation\u6709\u4e24\u4e2a\u601d\u8def\uff1a
\u4e00\u4e2a\u7a0b\u5e8f\u7531\u4e00\u7ec4\u6bb5(unordered set of)\u7ec4\u6210
\u6bcf\u4e2a\u90fd\u662f\u4e00\u4e2a\u6bb5\uff0c\u5728\u5185\u5b58\u4e2d\u4e0d\u4e00\u5b9a\u662f\u6309\u7167\u7528\u6237\u5199\u7684\u987a\u5e8f\u6392\u5217\u7684\uff0c\u987a\u5e8f\u5f88\u968f\u673a\u3002\u8fd9\u4e2a\u987a\u5e8f\u662f\u7f16\u8bd1\u5668\u6784\u5efa\u7684\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u7528\u4e00\u7ec4\u903b\u8f91\u5730\u5740(logical address)\u6216\u8005\u53eb\u865a\u62df\u5730\u5740(virtual address)\u6765\u8bbf\u95ee\u3002
\u903b\u8f91\u5730\u5740 = \u57fa\u5730\u5740 + \u6bb5\u754c
\u6211\u4eec\u6709\u4e00\u4e2asegment table\uff0c\u6bcf\u4e2a\u6761\u76ee\u4ee5segment-number\u7d22\u5f15\uff0c\u5b58\u50a8base\u548climit\uff08\u4e5f\u53ef\u80fd\u8fd8\u5305\u62ec\u6743\u9650\u4f4d\uff09\u3002
\u903b\u8f91\u5730\u5740\u7684\u6620\u5c04\u65b9\u5f0f\u5982\u4e0b\u56fe \u4ece\u903b\u8f91\u5730\u5740\u6620\u5c04\u5230\u7269\u7406\u5730\u5740\u7684\u8fd9\u4e00\u8fc7\u7a0b\u662f\u7531\u786c\u4ef6\u8bbe\u5907MMU\uff08memory-management unit\uff0c\u5185\u5b58\u7ba1\u7406\u5355\u5143\u5b8c\u6210\u7684\uff09\u3002CPU\u4f7f\u7528\u903b\u8f91\u5730\u5740\uff0c\u800c\u5bfb\u5740\u7684\u65f6\u5019\u5c31\u8981\u7528\u7269\u7406\u5730\u5740\u4e86\u3002 \u5206\u6bb5\u662f\u89e3\u51b3external fragmentation\u7684\u4e00\u79cd\u5c1d\u8bd5\uff0c\u56e0\u4e3a\u5b83\u628a\u7a0b\u5e8f\u5206\u6210\u4e86\u5f88\u591a\u6bb5\u3002
\u8fd9\u79cd\u65b9\u6cd5\u597d\u50cf\u4e5f\u88ab\u53eb\u505a\u6742\u5408\u65b9\u6cd5\uff0c\u56e0\u4e3a\u4e0d\u662f\u4e3a\u6574\u4e2a\u5185\u5b58\u7a7a\u95f4\u63d0\u4f9b\u9875\u8868\uff0c\u800c\u662f\u4e3a\u6bcf\u4e2a\u903b\u8f91\u5206\u6bb5\u63d0\u4f9b\u3002
"},{"location":"CS/OS/mem_file/#83-paging","title":"8.3 \u5206\u9875 Paging","text":"\uff08\u8fd9\u4e2a\u5730\u65b9\u6211\u771f\u7684\u771f\u7684\u6ca1\u770b\u61c2\uff0c\u53ef\u4ee5\u7559\u7740\u505alab\u518d\u770b\uff1a\u634f\u5417\u4eca\u5929lab\u5c31\u662f\u8fd9\u4e2a\u73a9\u610f\uff09
\u5141\u8bb8\u8fdb\u7a0b\u7684\u7269\u7406\u5730\u5740\u7a7a\u95f4\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u6848\u3002
\u6211\u4eec\u5c06physical memory\u5207\u6210\u7b49\u5927\u7684\u5757\uff082\u7684\u5e42\uff0c\u901a\u5e38\u4e3a4KB = 2^12 B\uff09\uff0c\u79f0\u4e3aframes\uff08\u5e27\uff09\u3002
\u5c06logical memory\u5207\u6210\u540c\u6837\u5927\u5c0f\u7684\u5757\uff0c\u79f0\u4e3apages\uff08\u9875\uff09\u3002
\u5728paging\u4e2d\u5bf9\u5e94\u5173\u7cfb\u6709\uff1a
MMU\u628alogical address\u7ffb\u8bd1\u6210physical address\u7684\u6b65\u9aa4\uff1a
\u4e3a\u4ec0\u4e48paging\u80fd\u6ee1\u8db3not contiguous\u5462\uff1f\u56e0\u4e3a\u6211\u4eec\u5728PC+1\u6307\u5411\u4e0b\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u53ea\u8981\u5728logical addr\u4e2d\u662f\u4e0b\u4e00\u6761\u6307\u4ee4\u5c31\u53ef\u4ee5\uff0c\u65e0\u6240\u8c13\u8fd9\u4e2alogical addr\u5bf9\u5e94\u7684physical addr\u5728\u54ea\u91cc\u3002\u6211\u4eec\u518d\u56de\u5fc6\u4e00\u4e0blogical addr\u7684\u683c\u5f0f\u5982\u4e0b \u53ef\u89c1d\u662f2^n+1\u65f6 +1 \u662f
\uff08\u5c31\u662f\u4e8c\u8fdb\u5236\u8fdb\u4e86\u4f4d\uff09\u3002\u8fd9\u65f6\u4e00\u4e2apage\u7ed3\u675f\uff0c\u8fdb\u5165\u4e86\u4e0b\u4e00\u4e2apage\u3002logical addr\u4ecd\u7136\u662f\u8fde\u7eed\u7684\u3002
\u786c\u4ef6\u652f\u6301 Hardware Support\uff1apage table\u7684\u786c\u4ef6\u5b9e\u73b0\u6709\u5f88\u591a\u65b9\u6cd5
Translation look-aside buffer (TLB)
\ud83d\udca1 TLB\u548c\u4e00\u822c\u7684cache\u4ec0\u4e48\u533a\u522b\uff1a
TLB\u7528\u4e8e\u5b58\u50a8\u865a\u62df\u5730\u5740\u548c\u7269\u7406\u5730\u5740\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b83\u662fpage table\uff08\u5185\u5b58\u5b50\u96c6\uff09\u7684\u4e00\u4e2acache\u3002
cache\u5b58\u50a8\u6700\u8fd1\u4f7f\u7528\u8fc7\u7684\u6570\u636e\u3002\u5b83\u662f\u6574\u4e2a\u5185\u5b58\u7684cache\u3002
\u6362\u9875\u7684\u7b56\u7565\u6709\uff1aLRU\uff0cround-robin\uff0crandom\u7b49\u3002
TLB with Address-Space Identifier (ASID)
Effective Memory-access Time
hit ratio = \u6ca1\u6709\u53d1\u751fTLB miss\u7684\u6b21\u6570\u7684\u767e\u5206\u6bd4
\u6bcf\u4e00\u6b21\u5185\u5b58\u8bbf\u95ee\u7684\u7528\u65f6\u4e3at\uff0c\u90a3\u4e48TLB hit\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee\u5b57\u8282\u603b\u5171\u7528\u65f6r\uff0cmiss \u7528\u65f62r
\u6709\u6548\u5185\u5b58\u8bbf\u95ee\u65f6\u95f4effective memory-access time EAT = tr + 2t(1-r) = t(2-r)
\u76f8\u6bd4\u76f4\u63a5\u5c06page table\u4fdd\u5b58\u5728\u5bc4\u5b58\u5668\uff0c\u5e73\u5747\uff08\uff1f\uff09\u5185\u5b58\u8bbf\u95ee\u65f6\u95f4\u591a\u4e86 [t(2-r)-t]/t = 1-r\u3002
"},{"location":"CS/OS/mem_file/#lab3","title":"\u591a\u7ea7\u9875\u8868\uff08lab3\u7528\u5230\u7684\uff09","text":"\u53e6\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5206\u6bb5\uff0c\u4f46\u4e5f\u80fd\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5\uff1a\u8bd5\u56fe\u53bb\u6389\u9875\u8868\u4e2d\u6240\u6709\u65e0\u6548\u533a\u57df\uff0c\u800c\u4e0d\u662f\u5c06\u5b83\u4eec\u5168\u90e8\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u3002
\u79f0\u4e3a\u591a\u7ea7\u9875\u8868\uff0c\u5c06\u7ebf\u6027\u8868\u53d8\u6210\u4e86\u7c7b\u4f3c\u6811\u7684\u4e1c\u897f\u3002
\u9996\u5148\u5c06\u9875\u8868\u5206\u6210\u9875\u5927\u5c0f\u7684\u5355\u5143\uff0c\u5982\u679c\u6574\u9875\u7684\u9875\u8868\u9879PTE(page table entry, \u9875\u8868\u6761\u76ee)\u65e0\u6548\uff0c\u5c31\u5b8c\u5168\u4e0d\u5206\u914d\u8be5\u9875\u7684\u9875\u8868\u3002\u4e3a\u4e86\u8ffd\u8e2a\u9875\u8868\u7684\u9875\u662f\u5426\u6709\u6548\uff08\u5982\u679c\u6709\u6548\uff0c\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\uff09\uff0c\u4f7f\u7528\u540d\u4e3a\u9875\u76ee\u5f55\u7684\u65b0\u7ed3\u6784\u3002\u9875\u76ee\u5f55\u544a\u8bc9\u9875\u8868\u7684\u9875\u5728\u54ea\u91cc\uff0c\u6216\u8005\u9875\u8868\u7684\u6574\u4e2a\u9875\u4e0d\u5305\u542b\u6709\u6548\u9875\u3002
\u4f8b\u5b50\uff1a
\u4e0b\u56fe\u4e2d\uff0c\u5de6\u8fb9\u662f\u4e00\u7ea7\u9875\u8868\uff0c\u5c3d\u7ba1\u7b2c\u4e8c\u4e09\u9875\u6ca1\u6709\u6709\u6548\u5730\u5740\uff0c\u4f46\u662f\u4ecd\u7136\u8981\u5206\u914d\u5185\u5b58\u3002
\u53f3\u8fb9\u662f\u4e8c\u7ea7\u9875\u8868\uff0c\u53ef\u4ee5\u770b\u5230\u9875\u8868\u76ee\u5f55\u4ec5\u4e3a\u7b2c\u4e00\u548c\u6700\u540e\u4e00\u9875\u5206\u914d\u5185\u5b58\uff0c\u91ca\u653e\u4e86\u4e2d\u95f4\u7684\u5185\u5b58\u7a7a\u95f4\u3002 \u4e0ePTE\u76f8\u4f3c\uff0c\u9875\u8868\u76ee\u5f55\u6709\u4e2aPDE\uff08\u8868\u793a\u6574\u4e2a\u9875\u8868\u91cc\u7684PTE\u7684\u6216\uff09
\u4f18\u70b9
\u7f3a\u70b9
\u6211\u4eec\u8ba8\u8bba\u4e00\u79cd\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684\u7684\u4e00\u90e8\u5206\u53ef\u4ee5\u4e0d\u5728\u5185\u5b58\u91cc\uff0c\u800c\u662f\u88ab\u4ea4\u6362\u5230\u4e00\u4e2a\u5907\u4efd\u5b58\u50a8\uff08backing store\u4e2d\uff09\uff0c\u76f4\u5230\u7ee7\u7eed\u8fd0\u884c\u7684\u65f6\u5019\u518d\u62ff\u56de\u5230\u5185\u5b58\u3002\u8fd9\u79cd\u601d\u60f3\u5f88\u50cfvirtual memory\u3002
\u6bd4\u5982\u5728paging\u673a\u5236\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u53easwap out\u4e00\u4e9bpages\u3002 swapping\u4f1a\u589e\u5927context switching\u7684\u65f6\u95f4\u5f00\u9500\u3002
"},{"location":"CS/OS/mem_file/#9","title":"9. \u865a\u62df\u5185\u5b58","text":"\u4e3a\u4ec0\u4e48\u9700\u8981\u865a\u62df\u5185\u5b58\uff1a\u8fdb\u7a0b\u7684\u4ee3\u7801\u5fc5\u987b\u5728\u5185\u5b58\u4e2d\uff0c\u56e0\u4e3aCPU\u53ea\u6709\u80fd\u529b\u8bbf\u95ee\u5185\u5b58\uff0c\u4e0d\u80fd\u8bbf\u95ee\u78c1\u76d8\u3002\u4f46\u662f\u4e0a\u4e00\u8282\u5f15\u5165\u7684swapping\u673a\u5236\u5141\u8bb8\u6211\u4eec\u628a\u4e00\u90e8\u5206\u5728\u4e3b\u5b58\u4e2d\u6682\u65f6\u7528\u4e0d\u5230\u7684\u5185\u5bb9\u4ea4\u6362\u5230disk\u4e2d\u3002
\u8fd9\u6837\u5c31\u9700\u8981\u6211\u4eec\u5f15\u5165\u903b\u8f91\u5730\u5740\u7a7a\u95f4(logical address space)\u7684\u6982\u5ff5\uff0c\u8981\u5927\u4e8e\u7269\u7406\u5730\u5740\u7a7a\u95f4(physical address space)\uff0c\u5bf9\u5e94\u7684\u9875\u8868\u4f1a\u63d0\u4f9b\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04\u3002
CPU\u8bbf\u95ee\u865a\u62df\u5730\u5740\u65f6\uff0c\u4f1a\u7531MMU\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u7269\u7406\u5730\u5740\u3002\u5982\u679cpage\u4e0d\u5728\u7269\u7406\u5185\u5b58\u4e2d\uff0c\u4f1a\u89e6\u53d1\u4e00\u6b21page fault\uff08exception\uff09\uff0c\u6709\u4e09\u79cd\u53ef\u80fd\u60c5\u51b5\uff1a
\u5728\u4e00\u6761\u6307\u4ee4\u6267\u884c\u671f\u95f4\uff0c\u53ef\u80fd\u89e6\u53d1\u591a\u6b21page fault\uff0c\u76f4\u5230\u89e3\u51b3\u540e\u6210\u529f\u8fd0\u884c\u3002
Kernel address & Userspace address
\u56e0\u4e3a\u6307\u4ee4\u6709privileged\u548cnon-privileged\uff0c\u5730\u5740\u7a7a\u95f4\u4e5f\u5206\u6210\u4e86kernel portion\u548cuser portion\uff0ckernel\u53ea\u80fdprivileged instruction\u8bbf\u95ee\uff0cuser\u90fd\u80fd\u3002\u6240\u6709\u8fdb\u7a0b\u7684kernel portion\u5176\u5b9e\u662f\u540c\u4e00\u5757\u4ee3\u7801\uff0c\u56e0\u4e3a\u6240\u6709\u8fdb\u7a0b\u7528\u5230\u7684\u90fd\u662f\u540c\u4e00\u5757kernel\u3002user portion\u8981\u590d\u5236\u662f\u56e0\u4e3a\u542b\u6709\u7684\u662f\u5404\u4e2a\u8fdb\u7a0b\u7684\u9875\u8868\u3001\u961f\u5217\u7b49\u4e1c\u897f\u3002
"},{"location":"CS/OS/mem_file/#91-lazy-allocation-demand-paging","title":"9.1 Lazy Allocation / Demand Paging","text":"OS\u5728\u5206\u914duser space\u65f6\uff0c\u4f1a\u4f7f\u7528lazy allocation\uff1a\u7528\u6237\u7533\u8bf7\u4e00\u5757\u5185\u5b58\u65f6\uff0cOS\u5e76\u4e0d\u4f1a\u771f\u6b63\u5728\u7269\u7406\u5185\u5b58\u4e2d\u5206\u914d\u5bf9\u5e94\u5185\u5b58\uff0c\u76f4\u5230\u771f\u6b63\u88ab\u8bbf\u95ee\u3002
\u8fd9\u6837\u8bbe\u8ba1\u7684\u539f\u56e0\u662f\u5f88\u591a\u7528\u6237\u7a0b\u5e8f\u7533\u8bf7\u7684\u5185\u5b58\u5927\u5c0f\u901a\u5e38\u6bd4\u771f\u6b63\u8981\u4f7f\u7528\u7684\u5927\u3002\u4f8b\u5982buffer\u3002
"},{"location":"CS/OS/mem_file/#92-copy-on-write","title":"9.2 Copy-on-write","text":"\u5141\u8bb8\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u4f7f\u7528\u540c\u4e00\u4e2a\u7269\u7406\u9875\u6765\u5de5\u4f5c\u3002
"},{"location":"CS/OS/mem_file/#93-page-replacement","title":"9.3 Page Replacement","text":"\u4ece\u5185\u5b58\u4e2d\u4ea4\u6362\u5230\u78c1\u76d8\u53bb\u4e00\u6574\u4e2a\u5f53\u524d\u4e0d\u5728\u4f7f\u7528\u7684frame\u3002
\u6b65\u9aa4\u662f\uff1a - \u627e\u5230\u8fd9\u4e2avictim frame - \u5c06\u5176\u5185\u5bb9\u5199\u5230\u4ea4\u6362\u9875\uff1a\u53ef\u4ee5\u7528\u4e00\u4e2adirty bit\uff0c\u5982\u679c\u6ca1\u6709\u6539\u8fc7\uff0c\u90a3\u5c31\u4e0d\u7528\u5199\u56de\u4e86 - \u4fee\u6539\u9875\u8868\uff08\u548cTLB\uff09\u4ee5\u8868\u793a\u5b83\u4e0d\u5728\u5185\u5b58\u4e2d\u4e86
\u627e\u5230victim frame\u7684\u505a\u6cd5 - Optimal\uff1a\u9009\u62e9\u6700\u957f\u65f6\u95f4\u5185\u4e0d\u518d\u8bbf\u95ee\u7684\u9875\u9762\u6362\u51fa\u3002\u662f\u7406\u60f3\u60c5\u51b5\uff0c\u5b9e\u9645\u5e76\u4e0d\u80fd\u9884\u6d4b\u672a\u6765\u8bbf\u95ee\u60c5\u51b5\u3002\u662f\u4e00\u79cd\u8bc4\u5224\u5176\u5b83\u7b97\u6cd5\u6027\u80fd\u7684\u7406\u8bba\u57fa\u51c6\u3002 - FIFO (First In First Out): \u5f88\u76f4\u89c9\u7684\u505a\u6cd5\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5f88\u591a\u9875\u9762\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u6240\u4ee5\u5148\u8fdbbuffer\u7684\u6709\u53ef\u80fd\u662f\u975e\u5e38\u7ecf\u5e38\u8bbf\u95ee\u7684\u3002\u5b83\u53ef\u80fd\u51fa\u73b0Belady\u2018s Anomaly\uff1a\u7269\u7406\u5e27\u589e\u52a0\uff0c\u5f02\u5e38\u60c5\u51b5\u53cd\u800c\u66f4\u591a\u4e86 - LRU (Least Recently Used)\uff1a\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u7684\u9875\u9762\u3002\u53ef\u4ee5\u6bcf\u4e2a\u9875\u8868\u52a0\u4e00\u4e2acounter\uff0c\u4e5f\u53ef\u4ee5\u7528\u6808\u4fdd\u5b58page numebrs\u3002\u5f00\u9500\u90fd\u633a\u5927\u3002 - LRU-Approximation\uff1a\u5f15\u5165\u4e00\u4e2areference bit\uff0c\u5f53\u88ab\u8bbf\u95ee\u65f6\u7f6e1\uff0cOS\u5b9a\u671f\u628a\u5b83\u7f6e0\u3002\u9700\u8981\u6362\u7684\u65f6\u5019\u5c31\u627e0\uff0c\u8bf4\u660e\u5b83\u5728\u6700\u8fd1\u8fd9\u4e00\u6bb5\u65f6\u95f4\u5185\u90fd\u6ca1\u88ab\u8bbf\u95ee\u8fc7\u3002\u6027\u80fd\u66f4\u597d\u4e86\u3002
"},{"location":"CS/OS/mem_file/#94-allocation-of-frames","title":"9.4 Allocation of Frames","text":"\uff08\u8fd9\u4e2a\u5730\u65b9\u5b8c\u5168\u6ca1\u770b\u61c2\uff09
\u7ed9\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u7684frame\u4e2a\u6570\uff1a
\u66ff\u6362\u65b9\u6cd5
\u5982\u679c\u9700\u8981\u4ece\u6700\u5927\u548c\u6700\u5c0f\u4e4b\u95f4\uff0c\u51b3\u5b9a\u4e00\u4e2a\u8fdb\u7a0b\u80fd\u591f\u4f7f\u7528\u7684page\u603b\u6570\uff0c\u6709\u591a\u79cd\u5206\u914d\u7b97\u6cd5
\u73b0\u4ee3\u8ba1\u7b97\u673a\u90fd\u6709\u591a\u4e2aCPU\uff0c\u6bcf\u4e2aCPU\u6bd4\u5176\u5b83CPU\u66f4\u5feb\u5730\u8bbf\u95ee\u5185\u5b58\u7684\u67d0\u4e9b\u90e8\u5206\u3002\u5982\u679c\u5dee\u5f02\u6bd4\u8f83\u660e\u663e\uff0c\u79f0\u8fd9\u79cd\u7cfb\u7edf\u4e3a\u975e\u5747\u5300\u5185\u5b58\u8bbf\u95ee\uff08NUMA\uff0cnon-uniform memory access\uff09\u7cfb\u7edf\u3002
"},{"location":"CS/OS/mem_file/#95-thrashing","title":"9.5 Thrashing","text":"\u5982\u679c\u8fdb\u7a0b\u53ef\u7528\u7684\u5e27\u8f83\u5c11\uff08\u5c11\u4e8e\u9891\u7e41\u8bbf\u95ee\u7684\u9875\u9762\u6570\u76ee\uff09\uff0c\u90a3\u4e48\u9891\u7e41\u51fa\u73b0page fault\u3002\u540c\u4e00\u4e2apage\u88ab\u9891\u7e41\u6362\u5165\u6362\u51fa\uff0c\u4ee5\u6ee1\u8db3\u8fd0\u884c\u7684\u8981\u6c42\u3002\u8fd9\u79cd\u9ad8\u5f3a\u5ea6\u9875\u9762\u8c03\u5ea6\u53eb\u6296\u52a8\uff08thrashing\uff09\uff0c\u5176\u9875\u9762\u8c03\u5ea6\u7528\u65f6\u751a\u81f3\u53ef\u80fd\u5927\u4e8e\u6267\u884c\u65f6\u95f4\u3002
"},{"location":"CS/OS/mem_file/#96-kernel-memory-allocation","title":"9.6 Kernel Memory Allocation","text":"kernel\u4e2d\u7684\u5f88\u591a\u6570\u636e\u7ed3\u6784\u5927\u5c0f\u533a\u5206\u6bd4\u8f83\u5927\uff0c\u5c0f\u7684\u53ef\u80fd\u4f1a\u5c0f\u4e8e\u4e00\u4e2apage\uff0c\u56e0\u6b64kernel\u7684\u8bbe\u8ba1\u5e94\u5f53\u5c3d\u91cf\u8282\u7701\u5185\u5b58\uff0c\u52aa\u529b\u51cf\u5c11\u788e\u7247\u3002\u539f\u56e0\u662f
\u4e24\u8005\u5bf9\u7269\u7406\u5185\u5b58\u7684\u8981\u6c42\u90fd\u6bd4\u8f83\u4e25\u683c
\u5206\u914d\u65b9\u6cd5
\u73b0\u4ee3\u8ba1\u7b97\u673a\u7684\u5927\u90e8\u5206\u4e8c\u7ea7\u5b58\u50a8\u7531hard disk drives (HDDs) \u548c nonvolatile memory (NVM) devices \u63d0\u4f9b\u3002
\u8bfe\u672c\u91cc\u8ba4\u4e3aNVM\uff08electronic\uff09\u4e0d\u5305\u542bHDD\uff08mechanical\uff09
HDD \u7ed3\u6784
\u53c2\u6570
NVM Devices
\u6bd4HDD\u66f4\u53ef\u9760\uff0c\u66f4\u5feb\uff0c\u66f4\u8d35\uff0c\u5bff\u547d\u77ed\uff0c\u5bb9\u91cf\u66f4\u5c0f
"},{"location":"CS/OS/mem_file/#102-hdd-scheduling","title":"10.2 \u78c1\u76d8\u8c03\u5ea6 HDD Scheduling","text":"\u4e3b\u8981\u4e3a\u4e86\u4f18\u5316\u4e24\u4e2a\u53c2\u6570
\u4e00\u822c\u4f1a\u8003\u8651minimize seek time\uff0c\u56e0\u4e3arotational latency\u4e00\u822c\u7ba1\u4e0d\u5230
First-Come First-Served (FCFS)
Advantages
Disadvantages:
Shortest seek time first (SSTF)
\u603b\u662f\u9009\u62e9\u8ddd\u79bb\u5f53\u524d\u6700\u8fd1\u7684request\u3002\u4e0d\u4e00\u5b9a\u6700\u597d
cannot calculate seek time in advance
high variance
\u53ef\u80fd\u5bfc\u81f4starvation
SCAN / Elevator algorithm
\u975e\u5e38\u5f62\u8c61\uff0c\u4e00\u76f4\u5f80\u4e00\u4e2a\u65b9\u5411\u8d70\u4e0d\u56de\u5934\uff0c\u76f4\u5230\u78b0\u5230\u8fb9\u754c\uff0c\u518d\u8fd4\u56de
long waiting time for requests that are just visited.
C-SCAN
\u4e0d\u662f\u8fb9\u8fd4\u56de\u8fb9\u626b\uff0c\u800c\u662f\u76f4\u63a5\u8fd4\u56de\u5f00\u5934
provides more uniform wait time than SCAN
LOOK / C-LOOK
\u5728 SCAN / C-SCAN \u7684\u57fa\u7840\u4e0a\uff0c\u53ea\u8d70\u5230\u6700\u5927/\u6700\u5c0f\u7684request\u7f16\u53f7\u5c31\u8fd4\u56de\uff0c\u800c\u4e0d\u662f\u8d70\u5230section\u7684\u5934\u3002
\u600e\u6837\u9009\u62e9scheduling algorithm\uff1a\u4e00\u822c\u9009\u62e9SSTF\uff0c\u5f53IO\u8d1f\u8377\u6bd4\u8f83\u5927\u65f6\uff0c\u9009\u62e9 LOOK / C-LOOK
"},{"location":"CS/OS/mem_file/#103","title":"10.3 \u78c1\u76d8\u7ba1\u7406","text":"\u78c1\u76d8\u683c\u5f0f\u5316\u6b65\u9aa4
boot block
\u5728\u521a\u6253\u5f00\u7535\u6e90\u6216\u91cd\u542f\u65f6\uff0c\u4e00\u4e2a\u81ea\u4e3e\uff08bootstrap\uff09\u7a0b\u5e8f\u4f1a\u521d\u59cb\u5316\u7cfb\u7edf\u7684\u5404\u4e2a\u90e8\u5206\uff0c\u5982CPU\u5bc4\u5b58\u5668\u3001\u8bbe\u5907\u63a7\u5236\u5668\u3001\u5185\u5b58\uff0c\u7136\u540e\u627e\u5230OS\u5185\u6838\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\uff0c\u4ece\u800c\u8fd0\u884cOS\u3002
\u4e00\u822cbootstrap\u7684\u542f\u52a8\u7a0b\u5e8ftiny bootstrap loader program\u5b58\u5728ROM\uff0c\u5b83\u5728\u78c1\u76d8\u4e2d\u7684boot partition\u628abootstrap\u7a0b\u5e8fload\u8fdb\u6765\u3002
"},{"location":"CS/OS/mem_file/#104-raid","title":"10.4 RAID","text":"\u78c1\u76d8\u5197\u4f59\u9635\u5217\uff08redundant array of independent disk, RAID\uff09\u6280\u672f\u3002
\u5b9a\u4e49\u597d\u50cf\u662f\u4e00\u4e2a\u62e5\u6709\u5927\u91cf\u78c1\u76d8\u7684\u7cfb\u7edf\uff0c\u6765\u6539\u5584\u6570\u636e\u7684\u8bfb\u5199\u901f\u7387\uff08\u56e0\u4e3a\u53ef\u4ee5\u5e76\u884c\uff09\uff0c\u4e14\u53ef\u9760\uff08\u4f7f\u7528\u5197\u4f59\u6765\u964d\u4f4e\u51fa\u73b0\u9519\u8bef\u7684\u671f\u671b\uff09\u3002
"},{"location":"CS/OS/mem_file/#11-io","title":"11. IO","text":""},{"location":"CS/OS/mem_file/#111","title":"11.1 \u65b9\u5f0f","text":"IO\u7cfb\u7edf\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u5c06\u4e0d\u540c\u7684IO\u8bbe\u5907\u7684\u5de5\u4f5c\u65b9\u5f0f\u5c01\u88c5\u5230\u4e00\u4e9b\u7c7b\u4e2d\uff0c\u4ece\u800c\u5f62\u6210\u8f83\u5c11\u7684\u901a\u7528\u7c7b\u578b\uff0c\u4e3a\u5e94\u7528\u7a0b\u5e8f\u9690\u85cf\u786c\u4ef6\u7684\u5177\u4f53\u5dee\u5f02\u3002
\u540c\u65f6\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u652f\u6301\u5e94\u7528\u7a0b\u5e8f\u900f\u660e\u5730\u5411\u4e00\u4e2a\u8bbe\u5907\u9a71\u52a8\u5668\u4f20\u8f93\u4efb\u610f\u6570\u636e\u3002\u5728UNIX\u4e2d\uff0c ioctl()
\u7cfb\u7edf\u8c03\u7528\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002\u8fd9\u4e00\u7cfb\u7edf\u8c03\u7528\u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08file descriptor\uff09\u6765\u786e\u5b9a\u4e00\u4e2a\u8bbe\u5907\uff0c\u56e0\u4e3aUNIX\u4e2d\u8bbe\u5907\u53ef\u4ee5\u901a\u8fc7\u6587\u4ef6\u7684\u65b9\u5f0f\u8bbf\u95ee\u3002
\u6587\u4ef6\u7cfb\u7edf\uff08file system\uff09\u662f\u4e3a\u4e86\u7ed9\u7528\u6237\u63d0\u4f9bdisk\u7684\u903b\u8f91\u89c6\u56fe\u3002
\u5e38\u89c1\u7684\u6587\u4ef6\u5c5e\u6027\u5b57\u6bb5
\u8fd9\u4e9b\u4fe1\u606f\u5b58\u5728\u76ee\u5f55\u7ed3\u6784\u91cc
\u6587\u4ef6\u64cd\u4f5c
\u6587\u4ef6\u6253\u5f00: \u6253\u5f00\u6587\u4ef6\u8868\uff08open-file table\uff09\uff0cfile-open count
\u6587\u4ef6\u9501\uff08file lock\uff09\uff1a\u7c7b\u4f3c\u4e8ereader-writer lock\u3002\u5206\u5171\u4eab\u9501\uff08shared lock\uff09\uff0c\u72ec\u5360\u9501\uff08exclusive lock\uff09\u3002\u5206\u5f3a\u5236\u9501\u5b9a\uff08mandatory lock\uff09\u548c\u5efa\u8bae\u9501\u5b9a\uff08advisory lock\uff09\u3002
\u6587\u4ef6\u7c7b\u578b\uff1a\u6587\u4ef6\u6269\u5c55\u540d\uff0c\u6216\u6587\u4ef6\u5934\u7684magic number
\u6587\u4ef6\u7ed3\u6784\uff1a
directory structure \u53ef\u4ee5\u6784\u5efa\u5728\u591a\u4e2avolume\u4e0a\uff0c\u8fd9\u4e9b\uff08\u522b\u7684\uff1f\uff09volume\u5fc5\u987b\u5148\u6302\u8f7d\uff08mount\uff09\u5230\u6587\u4ef6\u7cfb\u7edf\u7684\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u4f4d\u7f6e\u79f0\u4e3a\u6302\u8f7d\u70b9\uff08mount point\uff09\u3002
"},{"location":"CS/OS/mem_file/#125","title":"12.5 \u4fdd\u62a4","text":"Access Control List (ACL): \u6307\u5b9a\u6bcf\u4e2a\u7528\u6237\u53ca\u5141\u8bb8\u7684\u8bbf\u95ee\u7c7b\u578b\u3002
e.g. in Linux
\u6587\u4ef6\u7cfb\u7edf\u901a\u5e38\u5206\u5f88\u591a\u5c42
\u4e0a\u8ff0\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7528\u5230\u7684\u7279\u6b8a\u6570\u636e\u7ed3\u6784\u6709
In disk structures:
File control block (FCB) (per file)\uff1a\u4fdd\u5b58name, ownership, permissions, ref count, timestamps, pointers to data blocks on disk. \u6bcf\u4e2aFCB\u6709\u4e2a\u552f\u4e00\u6807\u8bc6\u53f7\uff0c\u4e0e\u76ee\u5f55\u6761\u76ee\u76f8\u5173\u8054\u3002
\u5728unix\u4e2dFCB\u53ebinode
\u5728NTFS\u4e2d\uff0c\u6bcf\u4e2aFCB\u662f\u4e00\u4e2a\u53ebmaster file table\u7684\u7ed3\u6784\u7684\u4e00\u884c\u3002 boot control block (per volume):
volume control block (per volume):
directory (per FS):
"},{"location":"CS/OS/mem_file/#133-vfs","title":"13.3 VFS \u865a\u62df\u6587\u4ef6\u7cfb\u7edf","text":"OS\u53ef\u4ee5\u540c\u65f6\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u6587\u4ef6\u7cfb\u7edf\u3002\u5b9a\u4e49\u4e86\u4e00\u5957\u901a\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u8bbf\u95ee\u63a5\u53e3\uff0copen(), read(), write(), close() \u548c file descriptiors \u7b49\uff0c\u4e0e\u5177\u4f53\u7684\u5b9e\u73b0\u5206\u79bb\u3002VFS\u8d1f\u8d23\u5bf9\u5e94\u8fd9\u4e9b\u63a5\u53e3\u548c\u5177\u4f53\u7684\u51fd\u6570\u6307\u9488\u3002
"},{"location":"CS/OS/mem_file/#134","title":"13.4 \u76ee\u5f55\u5b9e\u73b0","text":"\u4fdd\u5b58file name \u5230 FCB \u7684\u6620\u5c04\u5173\u7cfb\u3002
\u6587\u4ef6\u4fdd\u5b58\u5728disk blocks\u4e0a\u7684\u7b56\u7565\u3002
contiguous allocation: \u6bcf\u4e2a\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u5360\u6709\u7684blocks\u662f\u8fde\u7eed\u7684\u3002\u4f1a\u9020\u6210\u788e\u7247\u3002\u6587\u4ef6\u662f\u53ef\u6269\u5c55\u7684\u3002\u53ef\u4ee5\u5b9e\u73b0\u786e\u5b9a\u6bcf\u4e2a\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f\u3002\u4e5f\u53ef\u4ee5\u5f53\u7a7a\u95f4\u4e0d\u591f\u65f6\u7ef4\u62a4\u4e00\u4e2a\u6307\u9488\uff0c\u8bb0\u5f55\u6dfb\u52a0\u7684\u8fde\u7eed\u7a7a\u95f4\uff08extent\uff09\u7684\u4fe1\u606f\u3002\u76ee\u5f55\u9700\u8981\u8bb0\u5f55\u6bcf\u4e2a\u6587\u4ef6\u7684\u8d77\u6b62\u5730\u5740\u3002
linked allocation: \u6bcf\u4e2ablock\u8bb0\u5f55\u4e0b\u4e00\u5757\u7a7a\u95f4\u7684\u5730\u5740\uff0c\u6709\u70b9\u50cf\u94fe\u8868\u3002\u76ee\u5f55\u5219\u53ea\u8bb0\u5f55\u8d77\u6b62\u5730\u5740\u3002
indexed allocation: \u7ed9\u6bcf\u4e2a\u6587\u4ef6\u8bb0\u5f55\u4e00\u4e2a\u7d22\u5f15\u5757 (index block)\uff0c\u8bb0\u5f55\u6bcf\u4e2a\u6587\u4ef6\u7684\u7b2ci\u4e2a\u5757\u5728\u78c1\u76d8\u7684\u54ea\u4e2a\u5730\u65b9\u3002\u76ee\u5f55\u53ea\u9700\u8981\u4fdd\u5b58\u7d22\u5f15\u5757\u5728\u54ea\u91cc\u3002
"},{"location":"CS/OS/mem_file/#136","title":"13.6 \u7a7a\u95f2\u7a7a\u95f4\u7ba1\u7406","text":"\u53ef\u4ee5\u7528bitmap\uff0c\u75281\u6807\u8bb0\u7a7a\u95f2\u7684block\u3002\u4e3a\u4e86\u51cf\u5c11bitmap\u5360\u7528\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u4ee5cluster\u4e3a\u5355\u4f4d\u8bb0\u5f55\u3002
\u53ef\u4ee5\u5c06free space\u7528\u94fe\u8868\u94fe\u63a5\uff0c\u4f46\u8bbf\u95ee\u6548\u7387\u8f83\u4f4e\u3002
\u53ef\u4ee5\u5f15\u5165grouping\uff0c\u7ef4\u62a4\u82e5\u5e72\u4e2ablock\u5f62\u6210\u7684\u94fe\u8868\uff0c\u6bcf\u4e2ablock\u4fdd\u5b58\u82e5\u5e72\u7a7a\u95f2\u5757\u7684\u5730\u5740\u3002
counting\uff1a\u7ef4\u62a4\u8fde\u7eed\u7a7a\u95f2\u5757\u7684\u94fe\u8868\uff0c\u5373\uff0c\u94fe\u8868\u7684\u6bcf\u4e2a\u8282\u70b9\u662f\u8fde\u7eed\u7684\u7a7a\u95f2\u5757\u7684\u9996\u5757\u6307\u9488\u548c\u8fde\u7eed\u7684\u957f\u5ea6\u3002
"},{"location":"CS/OS/overview/","title":"OS Lecture Overview","text":""},{"location":"CS/OS/overview/#_1","title":"\u6210\u7ee9","text":"\u6559\u6750\uff1a\u53ea\u4e0a1-13
"},{"location":"CS/OS/overview/#1-overview","title":"1. \u64cd\u4f5c\u7cfb\u7edfoverview","text":""},{"location":"CS/OS/overview/#11","title":"1.1 \u57fa\u672c\u6982\u5ff5","text":""},{"location":"CS/OS/overview/#12","title":"1.2 \u64cd\u4f5c\u7cfb\u7edf\u5386\u53f2/\u7ed3\u6784\u7684\u79cd\u7c7b","text":"\u9664\u4e86kernel\u5916\uff0cOS\u8fd8\u5305\u542b\u4e00\u4e9bsystem programs\u8f85\u52a9kernel\u5de5\u4f5c\u3002\u5176\u5b83\u7a0b\u5e8f\u4e0d\u5c5e\u4e8eOS\uff0c\u88ab\u79f0\u4e3aapplication programs \u21d2 \u603b\u4e4b\uff0cOS\u662f\u8f6f\u4ef6\u4e2d\u6700\u57fa\u7840\u7684\u90e8\u5206\uff0c\u7528\u4ee5\u63a7\u5236\u548c\u7ba1\u7406\u7cfb\u7edf\u8d44\u6e90\uff0c\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u8ba1\u7b97\u673a\u3002
"},{"location":"CS/OS/overview/#13","title":"1.3 \u4e2d\u65ad","text":"\u6279\u5904\u7406\u7cfb\u7edf\u662f\u6700\u5bb9\u6613\u7406\u89e3\u7684\uff1a\u6bcf\u4e2a\u7a0b\u5e8f\u50cf\u4e00\u4e2a\u51fd\u6570\u4e00\u6837\u88abOS\u8c03\u7528\u3002
\u5176\u5b83\u7cfb\u7edf\uff1a\u7528\u5230\u4e2d\u65ad\uff08interrupt\uff09\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u90fd\u662f\u4e2d\u65ad\u9a71\u52a8\u7684
CPU\u786c\u4ef6\u6709\u4e00\u6761\u88ab\u79f0\u4e3ainterrupt-request line\u7684\u7ebf\u8def\uff0cCPU\u6bcf\u6267\u884c\u4e00\u6761\u6307\u4ee4\u540e\u90fd\u8981\u68c0\u6d4b\u4e00\u6b21\u3002\u5f53CPU\u4fa6\u6d4b\u5230\u4e00\u4e2a\u8bbe\u5907\u63a7\u5236\u5668\u5728\u8fd9\u6761\u7ebf\u8def\u4e0a\u53d1\u51fa\u7684\u4fe1\u53f7\u65f6\uff0c\u4f1a\u8bfb\u53d6interrupt number\u5e76\u4ee5\u6b64\u4f5c\u4e3ainterrupt vector\u4e2d\u7684index\u6765\u8df3\u8f6c\u5230\u5bf9\u5e94\u7684interrupt-handler routine\u3002
\u4e2d\u65ad\u5411\u91cf\u8868\uff08interrupt vector\uff09\u7528\u6765\u51cf\u5c11\u786e\u5b9a\u4e2d\u65ad\u670d\u52a1\u65f6\u7684\u67e5\u627e\u6b21\u6570\uff0c\u5373\u901a\u8fc7\u968f\u673a\u8bbf\u95ee\u800c\u4e0d\u662f\u904d\u5386\u7684\u65b9\u5f0f\u627e\u5230\u5904\u7406\u7a0b\u5e8f\u3002
\u5728\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u9700\u8981\u4e00\u4e9b\u66f4\u590d\u6742\u7684\u4e2d\u65ad\u5904\u7406\u529f\u80fd\uff1a
\u5728\u73b0\u4ee3\u7684\u8ba1\u7b97\u673a\u786c\u4ef6\u4e2d\uff0c\u8fd9\u4e9b\u7279\u65b0\u7531CPU\u548cinterrupt-controller hardware\u5b9e\u73b0\u3002
\u5927\u591a\u6570CPU\u6709\u4e24\u6761interrupt-request line
\u5728\u8c03\u7528\u51fd\u6570\u65f6\u9700\u8981\u4fdd\u5b58PC\u7b49\u73b0\u573a\u72b6\u6001\uff0c\u6267\u884c\u4e2d\u65ad\u65f6\u4e5f\u8981\u4fdd\u5b58\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4f4e\u7ea7\u4e2d\u65ad\u8981\u88ab\u9ad8\u7ea7\u4e2d\u65ad\u6253\u65ad\uff0c\u4f46\u662f\u4fdd\u5b58\u548c\u56de\u590d\u73b0\u573a\u72b6\u6001\u7684\u8fc7\u7a0b\u4e0d\u5e94\u5f53\u88ab\u6253\u65ad\u3002 \u8ba1\u65f6\u5668\u4e0e\u5206\u65f6\u7cfb\u7edf\u7684\u5b9e\u73b0\uff1a
\u5f53\u64cd\u4f5c\u7cfb\u7edf\u5c06CPU\u7684\u63a7\u5236\u6743\u4ea4\u7ed9\u4e00\u4e2a\u7a0b\u5e8f\u524d\uff0c\u4f1a\u8bbe\u5b9a\u597d\u4e00\u4e2a\u8ba1\u65f6\u5668timer\u3002timer\u901a\u8fc7\u4e00\u4e2a\u65f6\u949f\u548c\u4e00\u4e2a\u8ba1\u6570\u5668\u5b9e\u73b0\uff0c\u5f53\u8ba1\u6570\u5668\u7684\u503c\u4e3a0\u65f6\uff0c\u5c31\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\uff0c\u8fd9\u65f6\u63a7\u5236\u6743\u4ea4\u7ed9\u4e86OS\u3002\u53ef\u4ee5\u9632\u6b62\u7a0b\u5e8f\u6267\u884c\u65f6\u95f4\u8fc7\u957f\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u5206\u65f6\u7cfb\u7edf\u3002
"},{"location":"CS/OS/overview/#14","title":"1.4 \u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\uff0c\u7cfb\u7edf\u8c03\u7528","text":"Dual-mode & multimode
OS\u548c\u7528\u6237\u5171\u4eab\u8ba1\u7b97\u673a\u7684\u786c\u4ef6\u548c\u8f6f\u4ef6\u3002\u56e0\u6b64\uff0c\u4e00\u4e2a\u9519\u8bef\u7684\u7a0b\u5e8f\u53ef\u80fd\u5bfc\u81f4\u6574\u4e2a\u7cfb\u7edf\u5d29\u6e83\uff0c\u6216\u8005\u4f7f\u5f97\u5176\u5b83\u7528\u6237\u7684\u6570\u636e\u751a\u81f3OS\u672c\u8eab\u88ab\u4fee\u6539\u3002\u56e0\u6b64OS\u7684\u8bbe\u8ba1\u8981\u4fdd\u8bc1\u4e00\u4e2a\u9519\u8bef\u7684\u7a0b\u5e8f\u4e0d\u4f1a\u9020\u6210\u5176\u5b83\u7a0b\u5e8f\u7684\u9519\u8bef\u8fd0\u884c\u3002
\u7cfb\u7edf\u4ee3\u7801\u80fd\u8fd0\u884c\u7684\u6307\u4ee4\uff1aprivileged instructions
CPU\u6709\u4e00\u4e2amode bit\uff0c\u503c\u4e3a0\uff0c\u8868\u793a\u5f53\u524d\u5904\u4e8ekernel mode\uff08supervisor/system/privileged mode\uff09\uff0c\u503c\u4e3a1\u8868\u793a\u5904\u4e8euser mode\u3002\u6240\u6709\u7684interrupt handler\u90fd\u8fd0\u884c\u5728kernel mode\u3002
\u5982\u679c\u7528\u6237\u771f\u7684\u60f3\u6267\u884c\u7279\u6743\u6307\u4ee4\uff0c\u53ef\u4ee5\u7528system call\uff0c\u7531OS\u4ee3\u4e3a\u5b8c\u6210\u3002
OS\u80fd\u591f\u6267\u884c\u7684system call:
Process control - create process, terminate process - load, execute - get process attributes, set process attributes - wait event, signal event - allocate and free memory
File management - create file, delete file - open, close - read, write, reposition - get file attribute, set file attribute
Device management - request device, release device - read, write, reposition - get file attributes, set device attributes - logically attach or detach devices
Information maintenance - get time or date, set time or date - get system data, set system data - get process, file, or device attributes - set process, file, or device attributes
Communications - create, delete communication connection - send, receive messages - transfer status information - attach or detach remote devices
Protection - get file permissions - set file permissions
\u56e0\u6b64\u5f53\u53d1\u751f\u4e2d\u65ad\u3001system call\u3001\u9519\u8bef\uff08\u9664\u4ee50\uff0c\u6216\u8bbf\u95ee\u672a\u77e5\u6307\u4ee4\uff09\u7b49\u60c5\u51b5\u65f6\uff0c\u4f1a\u53d1\u751fuser mode\u5230
kernel mode\u7684\u8f6c\u6362
"},{"location":"CS/OS/process_syn/","title":"OS Lecture \u8fdb\u7a0b\u4e0e\u540c\u6b65","text":""},{"location":"CS/OS/process_syn/#2-process","title":"2. \u8fdb\u7a0b Process","text":""},{"location":"CS/OS/process_syn/#21","title":"2.1 \u7ec4\u6210","text":"\u8fdb\u7a0bprocess\uff08=\u4f5c\u4e1ajob\uff09\u662f\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u591a\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u5bf9\u5e94\u540c\u4e00\u4e2a\u7a0b\u5e8f\u3002\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684OS\u4e2d\u4f1a\u6709\u591a\u4e2a\u8fdb\u7a0b\uff0c\u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u6267\u884c\u8fc7\u7a0b\uff0c\u662fOS\u5206\u914d\u8d44\u6e90\u7684\u57fa\u672c\u5355\u4f4d\u3002
\u8fdb\u7a0b\u7684\u7ec4\u6210\uff1a\u4e00\u4e2a\u8fdb\u7a0b\u5305\u62ec - code or text - \u5373\u7a0b\u5e8f\u4ee3\u7801\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\u524d\u4ee5executable file\u7684\u5f62\u5f0f\u5b58\u50a8\u5728disk\u4e2d - program counter - PC\uff0c\u6307\u5411\u4e0b\u4e00\u4e2a\u8981\u8fd0\u884c\u7684\u6307\u4ee4 - counter of the processor\u2019s registers - \u5728\u8fdb\u7a0b\u4e4b\u95f4\u5207\u6362\u65f6\uff0c\u9700\u8981\u4fdd\u5b58\u5bc4\u5b58\u5668\u7684\u503c\u4ee5\u4fbf\u4e0b\u6b21\u56de\u5230\u8be5\u8fdb\u7a0b\u65f6\u7ee7\u7eed\u8fd0\u884c - run time stack - \u5728ICS\u548c\u6c47\u7f16\u4e2d\u5b66\u4e60\u8fc7\u76f8\u5173\u5185\u5bb9\uff0c\u5176\u4e2d\u7684\u6761\u76ee\u79f0\u4e3aactivation records\uff08stack frames\uff09 - \u7531\u7528\u6237\u4ee3\u7801\u63a7\u5236\uff08\u7f16\u8bd1\u65f6\u5b8c\u6210\u5173\u4e8e\u6808\u7684\u76f8\u5173\u8c03\u7528\uff09\uff0c\u5728\u8c03\u7528\u51fd\u6570\u65f6\u6682\u65f6\u5b58\u50a8\u4e00\u4e9b\u6570\u636e\uff0c\u5982local variables, return address, return values, state of registers, parameters\u7b49 - data section - global variables - heap - dynamically allocated memory
"},{"location":"CS/OS/process_syn/#22","title":"2.2 \u8fdb\u7a0b\u7684\u72b6\u6001","text":"\u8fdb\u7a0b\u5728\u6267\u884c(execute)\u65f6\u4f1a\u6539\u53d8\u72b6\u6001(state)\uff1a \u4e00\u4e2a\u5904\u7406\u5668\uff0c\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5running\uff0c\u66f4\u591a\u7684\u5904\u4e8eready\u6216waiting\u72b6\u6001
"},{"location":"CS/OS/process_syn/#23-process-control-block-pcb-aka-task-control-block","title":"2.3 \u8fdb\u7a0b\u63a7\u5236\u5757Process Control Block (PCB, aka. task control block)","text":"\u8868\u793a\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u6709\u4e14\u4ec5\u6709\u4e00\u4e2aPCB
PCB\u5305\u542b\u7684\u5173\u4e8e\u5f53\u524d\u8fdb\u7a0b\u7684\u4fe1\u606f\uff1a - process state \u8fdb\u7a0b\u72b6\u6001 - program counter - CPU registers \u8fdb\u7a0b\u76f8\u5173\u7684\u5bc4\u5b58\u5668\u7684\u503c - CPU scheduling information, properties, scheduling queue pointers, etc. - Memory-management information - Accounting information, CPU \u4f7f\u7528\u65f6\u95f4\uff0c\u65f6\u95f4\u671f\u9650\uff0c\u8bb0\u8d26\u6570\u636e\u7b49 - IO status information, \u5206\u914d\u7ed9\u8fdb\u7a0b\u7684IO\u8bbe\u5907\u5217\u8868\uff0c\u6253\u5f00\u6587\u4ef6\u5217\u8868\u7b49
PCB\u7ed3\u6784\u793a\u610f\u56fe \u4e0d\u540c\u7684\u7cfb\u7edf\u53ef\u80fd\u6709\u4e0d\u540c\u7684PCB\u3002Linux\u4e2d\u7684\u8fdb\u7a0b\u7528\u7ed3\u6784\u4f53task_struct\u5b58\u50a8\u3002
"},{"location":"CS/OS/process_syn/#24-pid","title":"2.4 \u8fdb\u7a0b\u7684\u521b\u5efa\uff0cpid","text":"OS\u901a\u8fc7\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff08process identifier, pid\uff09\u8bc6\u522b\u8fdb\u7a0b\u3002\u4e00\u4e2a\u8fdb\u7a0b\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b\uff0c\u5219\u5b83\u6210\u4e3a\u7236\u8fdb\u7a0b\uff0c\u65b0\u8fdb\u7a0b\u79f0\u4e3a\u5b50\u8fdb\u7a0b\u3002
\u7236\u8fdb\u7a0b\u7684pid\u79f0\u4e3a\u5b50\u8fdb\u7a0b\u7684ppid\uff08parent\u2019s pid\uff09\u2192 \u5f62\u6210\u8fdb\u7a0b\u6811\uff08process tree\uff09 \u5f53\u5b50\u8fdb\u7a0b\u521b\u5efa\u65f6\uff0c\u9700\u8981\u7684\u8d44\u6e90\uff08CPU\u65f6\u95f4\u3001\u5185\u5b58\u3001\u6587\u4ef6\u3001IO\u8bbe\u5907\u7b49\uff09\u53ef\u4ee5\u6765\u81eaOS\u4e5f\u53ef\u4ee5\u7ee7\u627f\uff08\u5171\u4eab\uff09\u81ea\u7236\u8fdb\u7a0b\u3002
UNIX\u7cfb\u7edf\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528fork()\u521b\u5efa\u65b0\u8fdb\u7a0b\uff0c\u76f8\u5f53\u4e8e\u62f7\u8d1d\u4e86\u4e00\u4efd\u7236\u8fdb\u7a0b\uff0c\u53ea\u6539\u53d8pid\u548cppid\uff0c\u7136\u540e\u628a\u5b50\u8fdb\u7a0b\u5f53\u524d\u5185\u5b58\u4f7f\u7528\u8bb0\u5f55\u8bbe0\u3002fork()\u7ed9\u7236\u8fdb\u7a0b\u8fd4\u56de\u503c\u662f\u5b50\u8fdb\u7a0b\u7684pid\uff0c\u7ed9\u5b50\u8fdb\u7a0b\u8fd4\u56de0\u3002
\u4ee3\u7801\u6bb5\uff1acreating a separate process using the UNIX fork() system call.
#include <sys/types.h>\n#include <stdio.h>\n#include <unist.h>\nint main()\n{\npid_t pid;\n/* fork a child process */\npid = fork();\nif (pid < 0){\n/* error occurred */\nfprintf(stderr, \"Fork Failed\");\nreturn 1;\n}\nelse if (pid == 0) {\n/* child process */\nexeclp(\"/bin/ls\", \"ls\", NULL);// \u5bf9\u4e8e\u7528\u6237\u7ed9\u51fa\u7684\u6307\u5b9a\u6587\u4ef6\u540d\uff0c\u7a0b\u5e8f\u4f1a\u5728\u5f53\u524dPATH\u73af\u5883\u53d8\u91cf\u4e0b\u641c\u7d22\n}\nelse {\n/* parent process */\n/* parent will wait for the child to complete */\nwait(NULL);\nprintf(\"child complete\");\n}\nreturn 0;\n}\n
fork() \u5982\u4f55\u5bf9\u7236\u8fdb\u7a0b\u548c\u5b50\u8fdb\u7a0b\u8fd4\u56de\u4e0d\u540c\u7684\u503c\uff1a\u5f53\u521b\u5efa\u65b0\u8fdb\u7a0b\u65f6\uff0c\u7236\u8fdb\u7a0b\u53ef\u4ee5
\u5b50\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u6709\u53ef\u80fd
\u4e3a\u4ec0\u4e48\u8981\u62f7\u8d1d\u4e00\u4efd\uff0c\u6709\u7684\u5b50\u8fdb\u7a0b\u4e0d\u4f1a\u7528copy\u7684\u5730\u5740\u3002\u6240\u4ee5\u90e8\u5206UNIX\u5f15\u5165\u4e86copy-on-write\u673a\u5236\uff0c\u5373\u5c06\u5730\u5740\u7a7a\u95f4\u7684\u590d\u5236\u63a8\u8fdf\u5230\u9700\u8981\u5199\u5165\u7684\u65f6\u5019\u518d\u8fdb\u884c\u3002
getpid()\u548cgetppid()\u53ef\u4ee5\u83b7\u5f97\u8fdb\u7a0b\u7684pid\u548cppid\u3002
"},{"location":"CS/OS/process_syn/#25","title":"2.5 \u8fdb\u7a0b\u7684\u7ec8\u6b62","text":"\u8fdb\u7a0b\u8c03\u7528exit()\u5b9e\u73b0\u7ec8\u6b62\u3002\u4e5f\u662fC\u8bed\u8a00main\u51fd\u6570\u8fd4\u56de\u65f6\u9690\u5f0f\u8c03\u7528\u7684\u4e1c\u897f
\u5f53\u8fdb\u7a0b\u7ec8\u6b62\u65f6\uff0c\u8fdb\u7a0b\u8fdb\u5165terminated\u72b6\u6001\uff0c\u5176\u8d44\u6e90\u88abOS\u56de\u6536\uff0c\u4f46\u662fpid\uff0c\u7ed3\u675f\u72b6\u6001\uff0c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u4ecd\u7136\u4f1a\u88ab\u4fdd\u5b58\uff0c\u56e0\u4e3a\u7236\u8fdb\u7a0b\u6709\u53ef\u80fd\u4f1a\u8c03\u7528wait()\u6765\u83b7\u53d6\u3002
zombie processes: \u5b50\u8fdb\u7a0b\u5df2\u7ec8\u6b62\uff0c\u7236\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u8c03\u7528wait()
orphan processes: \u7236\u8fdb\u7a0b\u7ed3\u675f\u4e86\uff0c\u5b50\u8fdb\u7a0b\u6ca1\u7ed3\u675f\u3002\u6709\u4e9bOS\u4f1a\u628a\u5b50\u8fdb\u7a0b\u7ed3\u675f\u6389\uff0cUNIX\u4f1a\u8ba9init\u79f0\u4e3a\u5176\u7236\u8fdb\u7a0b\u3002
"},{"location":"CS/OS/process_syn/#26-ipcinterprocess-communication","title":"2.6 \u8fdb\u7a0b\u95f4\u901a\u4fe1IPC\uff0cInterProcess Communication","text":"\u662f\u4e3a\u4e86\u5728\u8fdb\u7a0b\u7684\u8d44\u6e90\u76f8\u4e92\u9694\u79bb\uff08\uff1f\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u8ba9\u4e0d\u540c\u7684\u8fdb\u7a0b\u80fd\u76f8\u4e92\u8bbf\u95ee\u8d44\u6e90\uff0c\u534f\u8c03\u5de5\u4f5c\u3002
\u591a\u9053multiprogramming\u73af\u5883\u4e0b\uff0c\u8fdb\u7a0b\u7684\u4e2a\u6570\u901a\u5e38\u5927\u4e8eCPU\u4e2a\u6570\u3002
CPU\u8c03\u5ea6\u662fOS\u5173\u4e8e\u54ea\u4e2aready\u8fdb\u7a0b\u53ef\u4ee5\u8fd0\u884c\u548c\u8fd0\u884c\u591a\u4e45\u7684\u51b3\u5b9a\u3002
\u5177\u4f53\u6765\u8bb2\u4e00\u6b21\u8c03\u5ea6\u5e94\u8be5\u662f\u6307OS\u5c06\u4e00\u4e2a\u8fdb\u7a0b\u4ece5\u79cd\u72b6\u6001\u4e2d\u7684\u4e00\u79cd\u5207\u6362\u5230\u4e86\u53e6\u4e00\u79cd\u7684\u8fc7\u7a0b\u3002
\u76ee\u6807\u662f\u59cb\u7ec8\u5141\u8bb8\u67d0\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u4ee5\u6700\u5927\u5316CPU\u5229\u7528\u7387\uff0c\u540c\u65f6\u4fdd\u8bc1\u4e00\u5b9a\u516c\u5e73\u6027\u3002
\u8c03\u5ea6\u4e0d\u4e00\u5b9a\u662fCPU\u8c03\u5ea6\uff0c\u6709\u53ef\u80fd\u53d1\u751f\u5728\u6240\u6709\u573a\u666f\u3002
\u8c03\u5ea6\u7684\u539f\u56e0\u662f\u80fd\u591f\u4f9b\u7ed9\u7684\u8d44\u6e90\u6570\u91cf\u8fdc\u5c0f\u4e8e\u8bf7\u6c42\u7684\u6570\u91cf\u3002
"},{"location":"CS/OS/process_syn/#31","title":"3.1 \u8c03\u5ea6\u7684\u65f6\u673a","text":"CPU\u8c03\u5ea6\u51fa\u73b0\u5728\u4efb\u610f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u6709\u5982\u4e0b5\u79cd\u8f6c\u6362
\u597d\u770b\u4e00\u70b9\u7684\u770b\u56fe\u5427 \u8c03\u5ea6\u6309\u65f6\u673a\u5206\u7c7b\u5206\u4e24\u79cd
\u8c03\u5ea6\u7684\u8fc7\u7a0b\u5c31\u662f\u4e0a\u4e0b\u6587\u5207\u6362\uff0c\u611f\u89c9\u8fd9\u4e2a\u540d\u5b57\u8bf4\u7684\u662f\u5bf9\u4e8e\u6b63\u5728\u8fd0\u884c\u7684CPU\u91cc\u7684\u8fdb\u7a0b\uff0c\u6240\u8c13\u4e0a\u4e0b\u6587\u5c31\u662fPCB\u5185\u5bb9\u3002
"},{"location":"CS/OS/process_syn/#33","title":"3.3 \u8c03\u5ea6\u7b97\u6cd5\u8bc4\u4ef7","text":"\u8fd9\u4e9b\u76ee\u6807\u53ef\u80fd\u7684\u51b2\u7a81\uff1a - context switch vs. throughput - context switch vs. response time
"},{"location":"CS/OS/process_syn/#34","title":"3.4 \u8c03\u5ea6\u7b97\u6cd5","text":"First-come first-serve (FCFS) | Nonpreemptive
\u5148\u7533\u8bf7CPU\u7684\u8fdb\u7a0b\u5148\u7528\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2aFIFO\u961f\u5217\u5b9e\u73b0\u3002
\u5b83\u4f1a\u5bfc\u81f4convey effort: short process behind long process, \u5c24\u5176\u662f\u5f53\u6709\u7ebf\u7a0b\u8fdb\u5165waiting\u540e\uff0c\u518d\u8fd4\u56de\u7684\u65f6\u5019\u53c8\u8981\u91cd\u65b0\u6392\u961f\u3002
Shortest-job-first (SJF)
SJF\u7684\u6838\u5fc3\u60f3\u6cd5\u662f\u8ba9\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4\u6700\u77ed\u7684\u8fdb\u7a0b\u5148\u6765\u8fd0\u884c \u21d2 \u80fd\u5f97\u5230\u6700\u5c11\u7684\u5e73\u5747\u7b49\u5f85\u65f6\u95f4
\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4 = \uff08\u975e\u62a2\u5360\u5f0f\u8c03\u5ea6\uff09\u8fdb\u7a0b\u603b\u65f6\u95f4\uff08\u56e0\u4e3a\u8fdb\u7a0b\u4e0d\u53ef\u80fd\u88ab\u6253\u65ad\uff09=\uff08\u62a2\u5360\u5f0f\u8c03\u5ea6\uff09\u8fdb\u7a0b\u7684\u5269\u4f59\u8fd0\u884c\u65f6\u95f4
\u4f1a\u5206\u5f00\u8ba1\u7b97\u5c31\u884c
SJF\u5728\u4e24\u79cd\u8c03\u5ea6\u65b9\u6cd5\u90fd\u80fd\u83b7\u5f97\u6700\u5c0f\u5e73\u5747\u7b49\u5f85\u65f6\u95f4
\u95ee\u9898\u662f\u6211\u4eec\u4e0d\u77e5\u9053\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4 \u2192 \u6240\u4ee5\u8981\u731c\uff0c\u731c\u7684\u7b97\u6cd5\u662f\u4e4b\u524dCPU\u6267\u884c\u957f\u5ea6\u7684\u6307\u6570\u5e73\u5747
Round-robin (RR) in preemptive
\u505a\u6cd5\uff1a\u5b9a\u4e49\u4e00\u4e2a\u65f6\u95f4\u7247\uff08time slice/time quantum\uff09\uff0c\u5373\u4e00\u4e2a\u56fa\u5b9a\u7684\u8f83\u5c0f\u7684\u65f6\u95f4\u5355\u5143\uff0c\u5982\u679cprocess\u4e0d\u662f\u552f\u4e00\u5728ready queue\u4e2d\u7684\u8fdb\u7a0b\uff0c\u90a3\u5c31\u4e0d\u4f1a\u8fde\u7eed\u8fd0\u884c\u8d85\u8fc7\u4e00\u4e2a\u65f6\u95f4\u7247\u7684\u65f6\u95f4\u3002ready queue\u662fFIFO\u7684\u3002
\u6027\u80fd\uff1a\u6bd4\u8d77SJF\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u66f4\u957f\uff0c\u4f46\u662f\u964d\u4f4e\u4e86response time\u3002\u6027\u80fd\u597d\u574f\u57fa\u672c\u4e0a\u53d6\u51b3\u4e8e\u65f6\u95f4\u7247\u5927\u5c0f\uff0cresponse time\u548coverhead\u51b2\u7a81\u3002\u5982\u679c\u65f6\u95f4\u7247\u2192inf\uff0c\u76f8\u5f53\u4e8eRR\u2192FCFS
\u65f6\u95f4\u7247\u4e00\u822c\u752810~100ms, context-switch\u4e00\u822c\u82b110mius
Priority Scheduling
\u4f18\u5148\u8c03\u5ea6\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u8fdb\u7a0b\uff08\u6839\u636e\u8bfe\u672c\u7684\u4f8b\u5b50\uff0c\u4f18\u5148\u7ea7\u597d\u50cf\u662f\u4e0d\u4f1a\u91cd\u590d\u7684\uff09
\u4f18\u5148\u7ea7\u6807\u51c6\uff1a
\u53ef\u4ee5\u7528priority queue\u5b9e\u73b0
\u53ef\u4ee5\u4e0eRR\u7ed3\u5408\uff0c\u8fd9\u65f6\u5019ready queue\u662f\u7528priority queue\u5b9e\u73b0\u7684
Priority Aging\uff1a\u89e3\u51b3indefinite blocking / starvation\uff0c\u5373\u4f4e\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u6267\u884c\u3002\u53ef\u4ee5\u6839\u636e\u7b49\u5f85\u65f6\u95f4\u9010\u6e10\u589e\u52a0priority\u3002
Multilevel Queue Scheduling
\u53ef\u4ee5\u5c06\u8fdb\u7a0b\u5206\u4e3a\u4e0d\u540c\u7684\u7ec4\uff0c\u6bcf\u4e2a\u7ec4\u5185\u6709\u4e0d\u540c\u8c03\u5ea6\u7b97\u6cd5\u7684ready queue\uff0c\u7ec4\u548c\u7ec4\u4e4b\u95f4\u4e5f\u8981\u8c03\u5ea6\u3002
\u7ec4\u5185\uff1a\u4e00\u822c\u524d\u53f0\u961f\u5217\u4f7f\u7528RR\u4ee5\u4fdd\u8bc1response\uff0c\u540e\u53f0\u53ef\u4ee5FCFS
\u7ec4\u95f4\uff1a\u901a\u5e38\u7ed9\u961f\u5217\u8bbe\u7f6e\u4f18\u5148\u7ea7\uff0c\u7528preemptive priority scheduling\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7ec4\u95f4time-slicing
Multilevel Feedback Queue Scheduling
\u4e0a\u4e00\u4e2a\u7248\u672c\u7684\u52a0\u5f3a\u7248\u3002\u5141\u8bb8\u8fdb\u7a0b\u5728\u7ec4\u95f4\u8fc1\u79fb\u3002
\u8fc7\u7a0b
\u8fd9\u79cd\u7b97\u6cd5\u7684performance\u6839\u636e\u5177\u4f53\u64cd\u4f5c\u7cfb\u7edf\u548c\u5177\u4f53\u5b9e\u73b0\u800c\u5f02\u3002
"},{"location":"CS/OS/process_syn/#4-threads","title":"4. \u7ebf\u7a0b threads","text":""},{"location":"CS/OS/process_syn/#41","title":"4.1 \u52a8\u673a\u548c\u6982\u5ff5","text":"\u5f00\u9500\uff1a
\u56e0\u4e3a\u82e5\u5e72\u8fdb\u7a0b\u53ef\u80fd\u5171\u4eab\u4e00\u4e9b\u5185\u5bb9\uff0c\u5982\u679cOS\u77e5\u9053\u8fd9\u4e9b\u5171\u4eab\uff0c\u5c31\u80fd\u51cf\u5c11\u65b0\u5efa\u8fdb\u7a0b\u7684\u5f00\u9500\u53ca\u8fdb\u7a0b\u5207\u6362\u7684\u65f6\u5ef6\u3002
\u21d2 \u5f15\u5165\u7ebf\u7a0bthreads\uff0c\u7ebf\u7a0b\u5c5e\u4e8e\u8fdb\u7a0b
\u5b83\u4e5f\u6709thread id (tid), PC, register set \u548c runtime stack\u3002
\u7ebf\u7a0b\u4e0e\u540c\u4e00\u8fdb\u7a0b\u7684\u5176\u5b83\u7ebf\u7a0b\u5171\u4eabcode section, data section, heap, open files, signals
Linux\u4e2d\u7ebf\u7a0b\u4e5f\u53eb\u8f7b\u91cf\u7ea7\u8fdb\u7a0bLight Weight Process\u3002
\u5982\u679cOS\u652f\u6301\u7ebf\u7a0b\uff0c\u90a3\u8c03\u5ea6\u7684\u5c31\u662f\u5185\u6838\u7ea7\u7ebf\u7a0b\u800c\u4e0d\u662f\u8fdb\u7a0b\uff0c\u4e5f\u5c31\u662f\u8bf4\u7ebf\u7a0b\u662f\u8fd0\u884c\u4ee5\u53caCPU\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u5143\u3002
\u533a\u5206\uff1a\u8fdb\u7a0b\u662f\u5206\u914d\u8d44\u6e90\u7684\u57fa\u672c\u5355\u5143
"},{"location":"CS/OS/process_syn/#42","title":"4.2 \u4f18\u7f3a\u70b9","text":"\u591a\u7ebf\u7a0b\u7f16\u7a0bMulti-Threaded Programming\u7684\u4f18\u70b9\u6709\uff1a
\u7f3a\u70b9
- \u7528\u6237\u7ea7\u7ebf\u7a0buser-level thread\uff1a\u5728OS\u4e0a\u53ea\u662f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u5305\u542b\u7ebf\u7a0b\u5e93thread library\uff0c\u8d1f\u8d23\u7ebf\u7a0b\u7684\u521b\u5efa\u548c\u5207\u6362\uff1b\u5185\u6838\u7ea7\u7ebf\u7a0b\u7531OS\u652f\u6301\u8fd9\u4e9b\u64cd\u4f5c - \u7528\u6237\u901a\u8fc7OS\u63d0\u4f9b\u7684\u7ebf\u7a0b\u5e93\u51fd\u6570\u521b\u5efa\uff0c - \u4f18\u70b9\uff1a1\uff09\u4e0d\u5360\u7528OS\u7684tid\uff0c\u7406\u8bba\u4e0a\u53ef\u4ee5\u652f\u6301\u6bd4\u5185\u6838\u7ea7\u7ebf\u7a0b\u66f4\u591a\u7684\u7ebf\u7a0b\u6570 2\uff09\u8c03\u5ea6\u7b49\u64cd\u4f5c\u5728\u7528\u6237\u6001\uff0c\u4e0d\u9700\u8981\u8fdb\u5165\u5185\u6838\u6001 3\uff09\u5bb9\u6613\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u8c03\u5ea6\u7b97\u6cd5 - \u7f3a\u70b9\uff1a1\uff09\u4e00\u65e6\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u963b\u585e\uff0c\u90a3\u4e48OS\u770b\u6765\u5c31\u662f\u6574\u4e2a\u8fdb\u7a0b\u88ab\u963b\u585e\u4e86\uff0c\u5c31\u4f1a\u8ba4\u4e3a\u8be5\u8fdb\u7a0b\u7684\u5176\u5b83\u7ebf\u7a0b\u4e5f\u963b\u585e\u4e86\u3002\u5982\u679c\u662f\u5185\u6838\u7ea7\u7ebf\u7a0b\u5c31\u53ea\u963b\u585e\u8fd9\u4e2a\u7ebf\u7a0b 2\uff09\u540c\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\u7684\u591a\u4e2a\u7528\u6237\u7ea7\u7ebf\u7a0b\u65e0\u6cd5\u5728\u591a\u6838\u4e0a\u5206\u522b\u8fd0\u884c - \u5185\u6838\u7ea7\u7ebf\u7a0bkernel-level thread\uff1a
\u591a\u7ebf\u7a0b\u6a21\u578b\uff1a\u6709\u7684OS\u540c\u65f6\u652f\u6301\u7528\u6237\u7ea7\u548c\u5185\u6838\u7ea7\uff0c\u6709\u51e0\u79cd\u7528\u6237\u7ea7\u548c\u5185\u6838\u7ea7\u7684\u6620\u5c04\u65b9\u6cd5
\uff081\uff09\u7b49\u4e8e\u53ea\u652f\u6301\u7528\u6237\u7ea7 \uff082\uff09\u7b49\u4e8e\u53ea\u652f\u6301\u5185\u6838\u7ea7 \uff083\uff09m\u4e2a\u7528\u6237\u7ea7\u53ef\u4ee5\u6620\u5c04\u5230n\u4e2a\u5185\u6838\u7ea7 Linux\u7ebf\u7a0b\uff1a\u6ca1\u6709\u7279\u522b\u533a\u5206\u8fdb\u7a0b\u548c\u7ebf\u7a0b\uff0c\u90fd\u662f\u53ebtask
\u4e0d\u77e5\u9053\u8fd9\u91cc\u8003\u4e0d\u8003\u8981\u662f\u8003\u4e86\u56de\u53bbrefer\u4e00\u4e0b
5 \u7ebf\u7a0b - \u54b8\u9c7c\u6684\u7684\u4ee3\u7801\u7a7a\u95f4 (xuan-insr.github.io)
"},{"location":"CS/OS/process_syn/#5-synchronization","title":"5. \u540c\u6b65\u548c\u540c\u6b65\u5de5\u5177 Synchronization","text":"Synchronization\u5c31\u662f\u89c4\u5b9a\u8fdb\u7a0b\u6240\u505a\u7684\u5de5\u4f5c\u4e4b\u95f4\u7684\u987a\u5e8f\u6216\u8005\u5148\u5e8f\u5173\u7cfb\uff0c\u4ece\u800c\u9632\u6b62\u4e00\u4e9b\u975e\u6cd5\u60c5\u51b5\u53d1\u751f\u7684\u65b9\u6cd5\u3002
"},{"location":"CS/OS/process_syn/#51-cs-problem","title":"5.1 \u5f15\u5165\u548cCS Problem","text":"Cooperation process\u662f\u53ef\u4ee5\u5f71\u54cd\u7cfb\u7edf\u4e2d\u5176\u5b83\u8fd0\u884c\u8fdb\u7a0b\u6216\u88ab\u5176\u5b83\u8fdb\u7a0b\u5f71\u54cd\u7684\u8fdb\u7a0b\u3002
Cooperating System\u4f1a
e.g. Bounded-buffer problem
\u7ed9\u5b9a\u4e24\u4e2a\u8fdb\u7a0bproducer\u548cconsumer\uff0c\u5171\u7528\u5927\u5c0f\u4e3an\u7684buffer\u3002
producer\u751f\u4ea7\u6570\u636e\u653e\u5165buffer\uff0cconsumer\u4ecebuffer\u4e2d\u4f7f\u7528\u6570\u636e
\u9650\u5b9a\u6761\u4ef6\uff1aproducer\u4e0d\u5e94\u5728buffer\u6ee1\u65f6\u653e\u5165\u6570\u636e\uff0cconsumer\u4e5f\u4e0d\u5e94\u5f53\u5728buffer\u7a7a\u65f6\u53d6\u51fa\u6570\u636e
\u60f3\u8c61\u4e2d\u7684\u4e24\u4e2a\u8fdb\u7a0b
/* producer process */\nwhile (true){\n/* produce an item in nert_produced */\nwhile (count == BUFFER_SIZE)\n; /* do nothing */\nbuffer[in] = next_produced;\nin = (in+1) % BUFFER_SIZE;\ncount++;\n}\n/* Consumer Process */\nwhile (true){\nwhile (count == 0)\n; /* do nothing */\nnext_consumed = buffer[out];\nout = (out + 1) % BUFFER_SIZE;\ncount --;\n/* consume the item in next_consumed */\n}\n
\u5982\u679ccount\u7684\u503c\u662f\u9519\u8bef\u7684\uff1f \u4f8b\u5b50\u7684\u610f\u601d\u662f\uff0c++\u548c\u2014\u90fd\u662f\u7cfb\u7edf\u5b9e\u73b0\u7684\uff0c\u5982\u679c\u5171\u7528count\u8bfb\u53d6\u7684\u65f6\u95f4\u6070\u597d\u649e\u4e0a\uff0ccount\u7684\u503c\u5c31\u4e0d\u5bf9
\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u7684\u539f\u56e0\u662f\u6211\u4eec\u5141\u8bb8\u4e24\u4e2a\u8fdb\u7a0b\u540c\u65f6\u64cd\u7eb5\u53d8\u91cfcount\u3002
e.g. kernel\u4e2d\uff1a\u4e24\u4e2a\u8fdb\u7a0b P0\u00a0\u548c P1\u00a0\u540c\u65f6\u00a0fork()
\u00a0\u65f6\uff0c\u5982\u679c\u4e0d\u52a0\u9650\u5236\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u524d\u4f8b\u7684\u60c5\u51b5\uff0c\u5373\u5728\u67d0\u4e00\u4e2a\u8fdb\u7a0b\u628a\u5f53\u524d\u7684\u00a0next_avaliable_pid
\u00a0\u5206\u914d\u7ed9\u4ed6\u7684 child \u540e\uff0c\u5728\u6ca1\u6765\u5f97\u53ca\u66f4\u65b0\u00a0next_avaliable_pid
\u00a0\u524d\uff0c\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u4e86\u00a0next_avaliable_pid
\u00a0\u6765\u7ed9 child \u5206\u914d PID\uff0c\u8fd9\u5c31\u4f1a\u5bfc\u81f4\u4e24\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\u4f7f\u7528\u540c\u4e00\u4e2a PID \u7684\u60c5\u51b5\u3002
Race Condition\uff1a\u591a\u4e2a\u8fdb\u7a0b\u540c\u65f6\u64cd\u63a7\u4e00\u4e2a\u6570\u636e\uff0c\u7531\u64cd\u63a7\u51fa\u73b0\u7684\u987a\u5e8f\u51b3\u5b9a\u7ed3\u679c
\u5fc5\u987b\u4fdd\u8bc1\u540c\u4e00\u4e2a\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u64cd\u63a7\u67d0\u4e2a\u53d8\u91cf\u3002
The Critical-Section Problem \uff08CS Problem\uff09
\u8003\u8651\u4e00\u4e2a\u6709n\u4e2a\u8fdb\u7a0b\u7684\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u4e2d\u90fd\u6709\u4e00\u6bb5\u4ee3\u7801\u53ef\u80fd\u4fee\u6539\u5176\u4ed6\u81f3\u5c11\u4e00\u4e2a\u8fdb\u7a0b\u516c\u7528\u7684\u6570\u636e\uff0c\u79f0\u4e3acritical section\u3002\u8fd9\u4e2a\u7cfb\u7edf\u9700\u8981\u6ee1\u8db3\u7684\u91cd\u8981\u6027\u8d28\u662f\uff0c\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u6b63\u5728\u8fd0\u884ccritical section\u65f6\uff0c\u5176\u5b83\u8fdb\u7a0b\u90fd\u4e0d\u80fd\u8fdb\u5165critical section
\u5c06\u8fd9\u4e2a\u95ee\u9898\u79f0\u4e3acritical section problem\uff0c\u4e5f\u5c31\u662f\u8981\u8bbe\u8ba1\u4e00\u79cd\u8fbe\u6210\u4e00\u81f4\u884c\u7684\u65b9\u6cd5\u3002\u6216\u8005\u8bf4\u8bbe\u8ba1\u4e00\u79cd\u8ba9\u5404\u79cd\u8fdb\u7a0b\u540c\u6b65\u4ece\u800c\u5b89\u5168\u5171\u4eab\u6570\u636e\u7684\u534f\u8bae\u3002
\u8fd9\u6bb5\u7a0b\u5e8f\u7684\u793a\u610f\u56fe\u5982\u4e0b\uff1a \u6bcf\u4e2a\u8fdb\u7a0b\u5fc5\u987b\u5728entry section\u4e2d\u7533\u8bf7\u8fdb\u5165critical section\u7684\u8bb8\u53ef\uff1b\u5728critical section\u8fd0\u884c\u7ed3\u675f\u540e\u8fdb\u5165exit section\uff0c\u5728\u8fd9\u91cc\u8bb8\u53ef\u88ab\u91ca\u653e\u3002
\u2757\u2757\u2757
Critical section problem\u7684\u89e3\u51b3\u65b9\u6cd5\u5fc5\u987b\u6ee1\u8db3\u5982\u4e0b\u4e09\u4e2a\u8981\u6c42
\u63a5\u4e0b\u6765\u6211\u4eec\u4ecb\u7ecd\u7684\u7b97\u6cd5\u90fd\u662f\u5728\u4e00\u6b65\u4e00\u6b65\u6ee1\u8db3\u8fd9\u4e09\u4e2a\u8981\u6c42
Kernel\u4e2d\u7684CS Problem
\u9700\u8981\u4fdd\u8bc1kernel\u7684\u8bbe\u8ba1\u5b9e\u73b0\u4e86critical section
kernel\u7684\u5b9e\u73b0\u5206\u4e24\u79cd\u7c7b\u578b\uff1a
\u533a\u522b\u662f\u662f\u5426\u5141\u8bb8kernel mode\u88ab\u62a2\u5360
\u62a2\u5360\u5f0f\u5185\u6838\u66f4\u96be\u8bbe\u8ba1\uff0c\u4f46\u540c\u65f6\u4e5f\u54cd\u5e94\u66f4\u5feb\u3002
"},{"location":"CS/OS/process_syn/#52-petersons-solution","title":"5.2 Peterson\u2019s Solution","text":"\u7701\u6d41\uff1a\u8ba9\u4e24\u4e2a\u8fdb\u7a0b\u5171\u4eab\u4e00\u4e2a\u53d8\u91cf\uff0c\u65e2\u6709turn\uff08\u8f6e\u5230\u8c01\u80fd\u8fdb\u53bb\uff09\u4e5f\u6709flag\uff08\u8fdb\u7a0b\u662f\u5426ready\uff09\u3002\u5f53flag[\u67d0\u4e2a\u8fdb\u7a0b]\u4e14turn=\u8be5\u8fdb\u7a0b\uff0c\u5c31\u53ef\u4ee5\u8fdb\u53bb\u3002
\ud83d\udca1 \u60f3\u8981\u7406\u89e3PS\u7b97\u6cd5\uff0c\u8bf7\u60f3\u8c61\u4e24\u4e2a\u4eba\u4e92\u76f8\u8ba9\u5ea7\uff0cA\u5148\u8bf4\u4f60\u5750\u5427\uff0cB\u518d\u8bf4\u4f60\u5750\u5427\uff0c\u8fd9\u65f6A\u5750\u4e0b\u3002 A\u83b7\u5f97\u6905\u5b50\u6709\u4e24\u4e2a\u5145\u8981\u6761\u4ef6\uff1a A\u60f3\u5750: flag[A] = 1 \u5728B\u8ba9\u5ea7\u4e4b\u524d\uff0cA\u5df2\u7ecf\u8ba9\u8fc7\u5ea7\u4e86: turn \u2260 A \u8bf4\u660e\u4e4b\u524dturn\u66fe\u7ecf\u88ab\u8d4b\u4e3aA\uff0c\u73b0\u5728\u662fBint turn; // who is allowed to enter\nboolean flag[2]; // ready to enter its CS\nvoid foo(){\nwhile (true){\nflag[i] = true; // mark self ready\nturn = 1-i; // assert that if the other process wishes to enter its CS, it can do so;\nwhile (flag[1-i] && turn = 1-i); // wait\n/* critical section */\nflag[i] = false; // set ready to false\n/* reminder section */\n}\n}\n
\u5176\u4e2d i
\u662f0\u62161\uff0c\u8868\u793a\u7b2ci\u4e2a\u8fdb\u7a0b\u3002 turn
\u662f\u5f53\u524d\u6709\u6743\u8fdb\u5165critical section\u7684\u8fdb\u7a0b\uff080\u62161\uff09; flag
\u662f\u7b2ci\u4e2a\u8fdb\u7a0b\u662f\u5426\u51c6\u5907\u597d\u8fdb\u5165critical section\uff0c\u521d\u59cb\u503c\u5747\u4e3aFALSE\u3002
To enter the critical section, process Pi first sets flag[i]
to be true and then sets turn
to the value 1-i
(the other process), thereby asserting that is the other process wishes to enter the critical section, it can do so. If both processes try to enter at the same time, turn
will be set to both 0
and 1
at roughly the same time. Only one of these assignments will last; the other will occur but will be overwritten immediately. The eventual value of turn
determines which of the two processes is allowed to enter its critical section first.
Peterson\u2019s Solution\u6ee1\u8db3\u540c\u6b65\u7b97\u6cd5\u5fc5\u987b\u6ee1\u8db3\u7684\u4e09\u4e2a\u6027\u8d28\uff1a
Bakery Algorithm\uff1a
2\u4e2a\u8fdb\u7a0b\u7248\u672c\u7684PS\u3002\u9700\u8981\u904d\u5386\u6240\u6709\u8fdb\u7a0b\u67e5\u770b\u5927\u5bb6\u7684turn
Reordering \u91cd\u6392\u5e8f
PS\u7684\u7f3a\u70b9\u662f\u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u4e0a\u4e0d\u4e00\u5b9a\u9002\u7528\u3002\u56e0\u4e3a\u73b0\u4ee3\u7684\u5904\u7406\u5668\u548c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\u800c\u5bf9\u4e00\u4e9b\u8bfb\u5199\u64cd\u4f5c\u8fdb\u884c\u91cd\u6392\u3002
\u91cd\u6392\u7684\u65f6\u5019\u4f1a\u8003\u8651\u91cd\u6392\u5728\u5355\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\u7684\u5408\u7406\u6027\uff08\u8ba1\u7b97\u7ed3\u679c\u662f\u7a33\u5b9a\u4e14\u6b63\u786e\u7684\uff09\u3002\u4f46\u662f\u8fd9\u6837\u4e0d\u80fd\u4fdd\u8bc1\u5728\u591a\u7ebf\u7a0b\u5171\u7528\u6570\u636e\u65f6\u7684\u6b63\u786e\u6027\uff0c\u53ef\u80fd\u5728\u591a\u7ebf\u7a0b\u5171\u7528\u65f6\u51fa\u73b0\u4e0d\u786e\u5b9a\u6216\u4e0d\u5bf9\u7684\u8f93\u51fa\u3002
e.g. \u7f16\u8bd1\u5668\u548c\u5904\u7406\u5668\u53ef\u80fd\u4f1a\u5bf9\u6570\u636e\u8bfb\u53d6\u987a\u5e8f\u8fdb\u884creorder\uff0c\u4ee5\u4f7f\u4e0d\u9700\u8981\u4ea4\u66ff\u8bfb\u53d6\u4e24\u4e2a\u6570\u636e\u7684\u503c\uff0c\u800c\u662f\u76f8\u540c\u8bfb\u53d6\u653e\u5728\u4e00\u8d77\u3002
\u4e3a\u4e86\u89e3\u51b3\u91cd\u6392\u5e8f\u5bfc\u81f4\u7684\u5728\u591a\u7ebf\u7a0b\u4e0b\u4e0d\u7a33\u5b9a\uff0c\u6211\u4eec\u5f15\u5165\uff1a
Memory Barrier
\u5b83\u7528\u6765\u4fdd\u8bc1\u5176\u4e4b\u524d\u7684\u5185\u5b58\u8bbf\u95ee\u5148\u4e8e\u4e4b\u540e\u7684\u5b8c\u6210\u3002\u5373\uff0c\u5728\u67d0\u4e2a\u64cd\u4f5c\u524d\uff0c\u5185\u5b58\u7684\u6539\u53d8\u5bf9\u5176\u5b83\u5904\u7406\u5668\u4e0a\u7684\u8fdb\u7a0b\u90fd\u662f\u53ef\u89c1\u7684\u3002
\u52a0memory barrier\u7684\u4e00\u79cd\u65b9\u6cd5
while (!flag)\nmemory_barrier();\nprint x;\n
\u8fd9\u6837\u5c31\u4fdd\u8bc1\u4e86flag\u5728x\u4e4b\u524d\u88ab\u52a0\u8f7d\u4e86\u3002
Memory Model
\u53e6\u5916\uff0c\u5728\u73b0\u4ee3\u7684\u4f53\u7cfb\u7ed3\u6784\u4e0a\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u5199\u4e86\u5bf9\u5e94\u7684\u53d8\u91cf\u540e\u53ef\u80fd\u4e0d\u4f1a\u7acb\u5373\u5199\u56de\u5185\u5b58\uff0c\u8fd9\u4e5f\u6709\u53ef\u80fd\u5bfc\u81f4\u95ee\u9898\u3002
\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u51b3\u5b9a\u54ea\u5757\u5185\u5b58\u7ed9\u54ea\u4e2a\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u53eb\u505amemory model\u3002memory model\u6709\u4e24\u79cd\u7c7b\u578b
\u6709\u4e24\u4e2a\u786c\u4ef6\u6307\u4ee4\u80fd\u5e2e\u52a9\u5b9e\u73b0\u4e92\u65a5\u548c\u540c\u6b65
\u8bb8\u591a\u73b0\u4ee3\u7cfb\u7edf\u63d0\u4f9b\u786c\u4ef6\u6307\u4ee4\u6765\u4fee\u6539word\u7684\u5185\u5bb9\uff0c\u6216\u8005\u7528\u4e8eatomically (uniterruptably\uff0c\u4e0d\u53ef\u88ab\u6253\u65ad\u5730)\u4ea4\u6362\u4e24\u4e2aword\u3002
\u7528\u6237\u4e00\u822c\u4e0d\u7528\u5173\u5fc3\u7279\u5b9a\u673a\u5668\u6307\u4ee4\uff0c\u53ef\u4ee5\u7528\u6307\u4ee4 test_and_set()
\u548c compare_and_swap()
\u62bd\u8c61\u4e86\u89e3\u8fd9\u4e9b\u673a\u5668\u6307\u4ee4\u80cc\u540e\u7684\u542b\u4e49\u3002
test_and_set
\u7684\u5b9a\u4e49\u662f\u628a\u4e00\u4e2atrue\u8f93\u5165\u5230\u786c\u4ef6\uff0c\u5e76\u4e14\u628a\u53d8\u91cf\u539f\u6765\u7684\u503c\u8fd4\u56de\u3002\u5b83\u662f\u4e00\u4e2a\u57fa\u672c\u6307\u4ee4\u5668\u4ef6\u3002
bool test_and_set(bool *target) {\nbool rv = *target;\n*target = true;\nreturn rv;\n}\n
\u5b83\u7684\u91cd\u8981\u7279\u5f81\u662f\uff0c\u5b83\u7684\u6267\u884c\u662fatomic\u7684\u3002
\u8fd9\u4e2a\u6307\u4ee4\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0mutual exclusive: \u5b9a\u4e49\u4e00\u4e2abool\u53d8\u91cf lock
\uff0c\u521d\u59cb\u5316\u4e3afalse\u3002
\u4e3a\u4ec0\u4e48\u53ef\u4ee5\uff1a\u5982\u679c\u00a0lock
\u00a0\u5728 Entry Section \u65f6\u4e3a true\uff0c\u90a3\u4e48\u00a0test_and_set(&lock)
\u00a0\u5c06\u8fd4\u56de true\uff0c\u56e0\u6b64\u4f1a\u59cb\u7ec8\u5728 while \u5faa\u73af\u4e2d\u8be2\u95ee\u3002\u76f4\u5230\u67d0\u4e2a\u65f6\u523b\u00a0lock
\u00a0\u4e3a false\uff0c\u90a3\u4e48\u00a0test_and_set(&lock)
\u00a0\u5c06\u8fd4\u56de false \u540c\u65f6\u5c06\u00a0lock
\u00a0\u7f6e\u4e3a true\uff0c\u8fdb\u7a0b\u8fdb\u5165 Critical Section\uff0c\u540c\u65f6\u4fdd\u8bc1\u5176\u4ed6\u8fdb\u7a0b\u65e0\u6cd5\u8fdb\u5165 Critical Section\u3002\u5f53\u6301\u9501\u7684\u8fdb\u7a0b\u5b8c\u6210 Critical Section \u7684\u8fd0\u884c\uff0c\u5b83\u5728 Exit Section \u4e2d\u91ca\u653e\u00a0lock
\u00a0\uff0c\u4ece\u800c\u5141\u8bb8\u5176\u4ed6\u8fdb\u7a0b\u8fdb\u5165 Critical Section\u3002\u800c\u5982\u679c\u67d0\u4e2a\u65f6\u523b\u00a0lock
\u00a0\u4e3a false\uff0c\u800c\u6709\u4e24\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u51e0\u4e4e\u540c\u65f6\u8c03\u7528\u4e86\u00a0test_and_set(&lock)
\u00a0\u3002\u4f46\u7531\u4e8e\u5b83\u662f atomic\uff08none-or-all\uff09\u7684\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u8fd4\u56de false\u3002
\u4e0d\u80fd\u5b9e\u73b0bounded waiting\u600e\u4e48\u529e\uff0c\u6709\u7684\u8fdb\u7a0b\u53ef\u80fd\u5c31\u4e00\u76f4\u6ca1\u6709\u62ff\u5230\u9501\uff1a\u52a0\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u627e\u4e0b\u4e00\u4e2a\u53ef\u4ee5\u8fdb\u5165\u7684\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u6700\u591a\u7b49\u5168\u90e8\u904d\u5386\u5b8c\u4e00\u904d\u5c31\u8f6e\u5230\u81ea\u5df1
while (true){\n/* Entry Section */\nwhile (test_and_set(&lock))\n; /* do something */\n/* Critical Section */\n/* Exit Section */\nj = (i + 1) % n;\nwhile ((j != i) && !waiting[j]))\nj = (j + 1) % n;\nif (j == i)\nlock = false;\nelse\nwaiting[j] = false;\n/* Remainder Section */\n}\n
compare_and_swap()
\u7528\u8f6f\u4ef6\u6765\u5b9e\u73b0\u6027\u80fd\u975e\u5e38\u5dee\uff0c\u7528\u8f6f\u4ef6\u6765\u5b9e\u73b0\u4f1a\u53d8\u597d\u3002\u5b83\u7684\u5b9a\u4e49\u662f
int compare_and_swap(int *value, int expected, int new_value){\nint temp = *value;\nif (*value == expected)\n*value = new_value;\nreturn temp;\n}\n
\u53ef\u89c1\u5176\u5b9ecompare_and_swap()
\u4e0etest_and_set()
\u4f5c\u7528\u7c7b\u4f3c\u3002
\u7528compare_and_swap()
\u5b9e\u73b0mutual exclusive
while (true) {\n/* Entry Section */\nwhile (compare_and_swap(&lock, 0, 1) != 0)\n; /* do nothing */\n/* Critical Section */\n/* Exit Section */\nlock = 0;\n/* Remainder Section */\n}\n
"},{"location":"CS/OS/process_syn/#54-semaphores","title":"5.4 \u4fe1\u53f7\u91cf Semaphores","text":"\u662f\u4e00\u4e2a\u6574\u578b\u53d8\u91cf\uff0c\u9664\u4e86\u521d\u59cb\u5316\u5916\uff0c\u53ea\u80fd\u901a\u8fc7\u4e24\u4e2aatomic\u64cd\u4f5c wait()
\u548c signal()
\u6765\u8bbf\u95ee\u3002
void wait(S){\nwhile (S <= 0)\n; /* busy waiting */\nS--;\n}\nvoid signal(S){\nS++;\n}\n
\u6709\u4e24\u79cdsemaphore\uff1a
e.g. Consider P1 and P2 that require S1 to happen before S2, create a semaphore \u201csynch\u201d initialized to 0.
P1:\nS1;\nsignal(synch);\nP2:\nwait(synch);\nS2;\n
\u5982\u679c\u60f3\u8981\u89e3\u51b3semaphore\u7684busy waiting\u95ee\u9898\uff0c\u53ef\u4ee5\u5f15\u5165waiting queue
typedef struct {\nint value;\nstruct list_head * waiting_queue;\n} semaphore;\nwait(semaphore *S) {\nS->value--;\nif (S->value < 0) {\nadd this process to S->list;\nblock();\n}\n}\nsignal(semaphore *S) {\nS->value++;\nif (S->value <= 0) {\nremove a process P from S->list;\nwakeup(P);\n}\n}\n
\u53ef\u80fd\u4f1a\u5bfc\u81f4deadlock
"},{"location":"CS/OS/process_syn/#55-atomic-variable","title":"5.5 Atomic Variable","text":"\u90a3\u5c31\u76f4\u63a5\u7528compare_and_swap()
\u6765\u505a\u6210\u4e00\u4e9batomic\u7684\u673a\u5668\u6307\u4ee4\u5de5\u5177
e.g. count++ \u662f\u53ef\u4ee5\u6253\u65ad\u7684\uff0c\u4f46\u662f\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u4e0d\u53ef\u6253\u65ad\u7684increment(&count)
void increment(atomic_int *v){\nint temp;\ndo {\ntemp = *v;\n} while (temp != compare_and_swap(v, temp, temp+1)); // \u5b83\u4e0d\u4f1a\u88ab\u6253\u65ad\n}\n
\u8981\u8bb0\u5f97\u5b83\u53ea\u80fd\u89e3\u51b3\u53d8\u91cf\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u7684race condition\u3002\u6b64\u65f6\u53ea\u6709\u5f85\u66f4\u65b0\u53d8\u91cf\u4e00\u4e2a\u53d8\u91cf\u5728\u7b49\u5f85\u8bfb\u53d6\u3002\u5982\u679c\u6709\u4e24\u4e2aconsumer\u7b49\u5f85\u8bfb\u53d6\uff0c\u4f46count\u6539\u53d8\u65f6\u53ea\u4f1a\u4ea7\u751f\u4e00\u4e2a\u503c\u5728buffer\u91cc\uff0c\u90a3\u5c31\u4e0d\u884c\u3002
"},{"location":"CS/OS/process_syn/#56-mutex-mutual-exclusion-lock","title":"5.6 Mutex (Mutual Exclusion Lock)","text":"\u7528\u8f6f\u4ef6\u65b9\u6cd5\u89e3\u51b3CS\u3002
\u8ba9\u8fdb\u7a0b\u5148\u5728entry section\u7533\u8bf7acquire()\u4e00\u4e2a\u9501\uff0c\u7136\u540e\u5728exit section release()\u4e00\u4e2a\u9501\u3002\u7136\u540e\u7528\u4e00\u4e2abool\u53d8\u91cf\u6765\u770b\u5b83\u662f\u5426available
while (true){\nacquire();\n/* critical section */\nrelease();\n/* remainder section */\n}\nvoid acquire(){\nwhile (!available)\n; /* busy waiting */\navailable = false;\n}\nvoid release(){\navailble = true;\n}\n
\u56e0\u4e3a\u8fd8\u9700\u8981\u4fdd\u8bc1\u4e92\u65a5\uff0c\u9700\u8981\u4fdd\u8bc1acquire\u662f\u539f\u5b50\u6027\u7684\uff0c\u90a3\u5c31\u7528\u4e0a\u8ff0\u4e24\u4e2a\u786c\u4ef6\u5de5\u5177\u6765\u5b9e\u73b0\u3002\u4ee3\u7801\u540c\u5bf9\u5e94\u8282\uff0c\u4e0d\u8d58\u8ff0\u3002
\u7f3a\u70b9\uff1a\u9700\u8981busy waiting\uff0c\u5f53\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5728CS\u4e2d\u65f6\uff0c\u5176\u5b83\u8fdb\u7a0b\u9700\u8981\u5728acquire()\u4e2dspin\uff0c\u6240\u4ee5\u4e5f\u79f0\u4e3aspinlock\u3002\u5982\u679c\u6709N\u4e2a\u8fdb\u7a0b\u540c\u65f6\u4f7f\u7528\u4e00\u4e2aCPU\uff0c\u90a3\u4e48\u5c06\u5927\u7ea6\u6709(N-1)/N\u7684\u6d6a\u8d39\u3002\u5982\u679c\u6709\u8fdb\u7a0b\u5728\u4f01\u56feacquire\u4e00\u4e2a\u9501\u65f6\u88ab\u7ec4\u7ec7\uff0c\u79f0\u5b83\u4e3acontended\uff08\u88ab\u4e89\u593a\uff09\uff1b\u53cd\u4e4b\u79f0\u4e3auncontended\u3002
\u8fd8\u53ef\u4ee5\u8003\u8651\u4e0b\u9762\u7684\u8bbe\u8ba1\uff0c\u5176\u4e2dyield()\u4f1a\u4f7f\u7a0b\u5e8f\u4ecerunning\u8f6c\u4e3aready\uff0c\u4ece\u800c\u8ba9\u51faCPU
void acquire() {\nwhile (compare_and_swap(&avaliable, 1, 0) != 1)\nyield();\n}\nvoid release() {\navaliable = true;\n}\n
\uff08\u8fd9\u4e2a\u5730\u65b9\u771f\u7684\u771f\u7684\u6ca1\u770b\u61c2\uff09
"},{"location":"CS/OS/process_syn/#57-priority-inversion","title":"5.7 Priority Inversion","text":"e.g.
Three processes PL, PM and PN with priority PL < PM < PH.
PL holds a lock that was requested by PH \u2192 PH is blocked.
PM becomes ready and preempted the PL
It effectively inverts the relative priorities of PM and PH.
\u5177\u6709\u4e2d\u7b49\u4f18\u5148\u7ea7\u7684PM\u5f71\u54cd\u4e86\u9ad8\u4f18\u5148\u7ea7\u7684PH\u7684\u7b49\u5f85\u65f6\u95f4\uff0c\u8fd9\u6837\u662f\u4e0d\u5bf9\u7684\u3002
\u89e3\u51b3\u65b9\u6848\uff1a
\u53ef\u4ee5\u901a\u8fc7\u4f18\u5148\u7ea7\u7ee7\u627fpriority inheritance\u6765\u89e3\u51b3\u3002\u6240\u6709\u6b63\u5728\u8bbf\u95ee\u8d44\u6e90\u7684\u8fdb\u7a0b\uff08\u5982PL\uff09\u9700\u8981\u83b7\u5f97\u8bbf\u95ee\u8fd9\u4e2a\u8d44\u6e90\u7684\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff08PH\uff09\uff0c\u76f4\u5230\u5176\u7528\u5b8c\u6709\u5173\u8d44\u6e90\u4e3a\u6b62\u3002\u6bd4\u5982\u4e0a\u4f8b\u4e2d\uff0cPL\u4f1a\u4e34\u65f6\u7ee7\u627fPL\u7684\u4f18\u5148\u7ea7\uff0c\u7136\u540ePH\u8fd0\u884c\uff0c\u6700\u540ePM\u8fd0\u884c\u3002
"},{"location":"CS/OS/process_syn/#6","title":"6. \u7ecf\u5178\u540c\u6b65\u95ee\u9898","text":"\u4e00\u822c\u6211\u4eec\u7528\u4fe1\u53f7\u91cf\u89e3\u51b3\u95ee\u9898
\u4fe1\u53f7\u91cf\u7684\u903b\u8f91\uff1a\u4e00\u4e2a\u4fe1\u53f7\u91cf\u7528\u6765\u8868\u793a\u4e00\u7c7b\u201c\u8d44\u6e90\u201d\u7684\u4f59\u91cf\u3002wait()\u7b49\u5f85\u5230\u5176\u6709\u4f59\u91cf\u65f6\u4ece\u4e2d\u53d6\u8d70\u4e00\u4e2a\uff0c\u800csignal()\u91ca\u653e\u4e00\u4e2a\u8d44\u6e90\u3002
\uff08\u4e0a\u8fb9\u8fd9\u6bb5\u5728\u5199\u4ec0\u4e48\uff09
"},{"location":"CS/OS/process_syn/#61-bounded-buffer-problem","title":"6.1 Bounded-buffer Problem","text":"\ud83d\udca1 \u7ed9\u5b9a\u4e24\u4e2a\u8fdb\u7a0b\uff1aproducer\u548cconsumer\uff0c\u5171\u7528\u5927\u5c0f\u4e3an\u7684buffer\u3002producer\u751f\u4ea7\u6570\u636e\u653e\u5165buffer\uff0cconsumer\u4ecebuffer\u4e2d\u53d6\u51fa\u6570\u636e\u5e76\u4f7f\u7528\u4e4b\u3002 \u8be5\u95ee\u9898\u9700\u8981\u4fdd\u8bc1\uff1aproducer\u4e0d\u5e94\u5f53\u5728buffer\u6ee1\u65f6\u653e\u5165\u6570\u636e\uff0cconsumer\u4e5f\u4e0d\u5e94\u5f53\u5728buffer\u7a7a\u65f6\u53d6\u51fa\u6570\u636e\u3002\u9996\u5148\uff0c\u6839\u636e\u6211\u4eec\u5728\u524d\u4e00\u8282\u4e2d\u7684\u8ba8\u8bba\uff0cproduce\u548cconsume\u7684\u8fc7\u7a0b\u4f1a\u8bbf\u95ee\u5230buffer\u7684\u8d44\u6e90\uff0c\u56e0\u6b64\u8bbf\u95eebuffer\u662fcritical section\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u9501\uff08\u6216\u8005\u4fe1\u53f7\u91cf\uff09\u6765\u63a7\u5236\u5bf9buffer\u7684\u8bbf\u95ee\u3002
\u8ba8\u8bba\u4e86\u4e00\u4e0b\u9501\u6c38\u8fdc\u4e0d\u53ef\u80fd\u6709\u6700\u4f18\u89e3\uff1a\u6ca1\u770b\u61c2
semaphore lock = 1;\nsemaphore eslot = BUFFER_SIZE; // \u7a7a\u95f2buffer\u7684\u6570\u91cf\nsemaphore fslot = 0;\nproducer(){\nwhile (true){\nwait (eslot); // if buffer is full. i.e. eslot == 0, wait. else eslot --\nwait (lock);\nadd_to_buffer(next_produced);\nsignal(lock);\nsignal(fslot); // fslot ++\n}\n}\nconsumer(){\nwhile(true){\nwait(fslot); // if buffer is empty. i.e. fslot == 0, wait. else fslot--\nwait(lock);\nnext_consumed = take_from_buffer();\nsignal(lock);\nsignal(eslot); // eslot ++\n}\n}\n
"},{"location":"CS/OS/process_syn/#62-reader-writer-problem","title":"6.2 Reader-Writer Problem","text":"\ud83d\udca1 \u5bf9\u4e00\u4e2a\u6570\u636e\uff0creaders\u8bfb\uff0cwriters\u8bfb\u548c\u5199 \u8bbe\u8ba1\u65b9\u6848\u4fdd\u8bc1\uff1a\u591a\u4e2areaders\u53ef\u4ee5\u540c\u65f6\u8bfb\u53d6\uff0c\u4f46\u662fwriter\u8fdb\u884c\u8bfb\u5199\u65f6\u4e0d\u80fd\u6709\u5176\u5b83writers\u548creaders\u3002 semaphore write_lock = 1;\nint reader_count = 0;\nsemaphore reader_count_lock = 1;\nsemaphore writer_first = 1;\nwriter() {\nwhile (true) {\nwait(writer_first);\nwait(write_lock);\nread_and_write();\nsignal(write_lock);\nsignal(writer_first);\n}\n}\nreader() {\nwhile (true) {\nwait(writer_first);\nwait(reader_count_lock);\nreader_count++;\nif (reader_count == 1)\nwait(write_lock);\nsignal(reader_count_lock);\nsignal(writer_first);\nread();\nwait(reader_count_lock);\nreader_count--;\nif (reader_count == 0)\nsignal(write_lock);\nsignal(reader_count_lock);\n}\n}\n
"},{"location":"CS/OS/process_syn/#63-dining-philosophers-problem","title":"6.3 Dining-Philosophers Problem","text":"\ud83d\udca1 5\u4e2a\u54f2\u5b66\u5bb6\u4e00\u8d77\u5403\u996d\u3002\u6bcf\u4e24\u4e2a\u54f2\u5b66\u5bb6\u4e4b\u95f4\u6709\u4e00\u6839\u7b77\u5b50\uff0c\u6bcf\u4e2a\u4eba\u4e00\u6b21\u53ef\u4ee5\u62ff\u8d77\u4e00\u6839\u7b77\u5b50\uff0c\u62ff\u5230\u4e24\u6839\u7b77\u5b50\u7684\u5c31\u53ef\u4ee5\u5403\u4e00\u6bb5\u65f6\u95f4\uff0c\u5403\u5b8c\u601d\u8003\u4e00\u6bb5\u65f6\u95f4\u3002  \u4e09\u79cd\u89e3\u51b3\u65b9\u6848\uff1a
\u662f\u6307\u591a\u4e2a\u8fdb\u7a0b\u56e0\u7ade\u4e89\u8d44\u6e90\u5bfc\u81f4\u7684\u4e00\u79cd\u50f5\u5c40\uff0c\u5373\u82e5\u5e72\u8fdb\u7a0b\u5404\u6301\u6709\u4e00\u4e9b\u8d44\u6e90\uff0c\u540c\u65f6\u7b49\u5f85\u83b7\u53d6\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u6301\u6709\u7684\u8d44\u6e90\uff0c\u5f62\u6210\u7684\u4e92\u76f8\u7b49\u5f85\u5c40\u9762\u3002
e.g.
\u4e24\u4e2a\u8fdb\u7a0b\uff0c\u4e24\u4e2a\u78c1\u76d8\u9a71\u52a8\u5668
semaphore first_mutex = 1;\nsemaphore second_mutex = 1;\nthread_one() {\nwait(first_mutex); // \u6301\u6709\u4e00\u4e2a\nwait(second_mutex); // \u60f3\u8981\u53e6\u4e00\u4e2a\n// ...\n}\nthread_two() {\nwait(second_mutex);\nwait(first_mutex);\n// ...\n}\n
\u53ef\u4ee5\u901a\u8fc7\u5206\u914d\u4f18\u5148\u7ea7\u6765\u89e3\u51b3\uff0c\u4f46\u662f\u4f18\u5148\u7ea7\u53ef\u80fd\u5bfc\u81f4starvation
"},{"location":"CS/OS/process_syn/#71-system-resource-allocation-graph","title":"7.1 \u8d44\u6e90\u5206\u914d\u56fe system resource-allocation graph","text":"\u662f\u4e00\u79cd\u5bf9\u7cfb\u7edf\u8d44\u6e90\u548c\u60f3\u4f7f\u7528\u8d44\u6e90\u7684\u5b9e\u4f8b\u8fdb\u884c\u5efa\u6a21\u7684\u89c4\u8303\u5316\u4f5c\u56fe\u6807\u51c6
\u5047\u8bbe\u6709m\u4e2a\u8d44\u6e90(resources) R1\u2026 Rm\uff0c\u6bcf\u79cd\u8d44\u6e90\u6709W\u4e2a\u5b9e\u4f8b\uff08instance\uff09\u3002\u5404\u4e2a\u6d3b\u52a8\u8fdb\u7a0bP1\u2026Pn\u4f1a\u5229\u7528\u8fd9\u4e9b\u8d44\u6e90\uff0c\u6bcf\u4e2a\u8d44\u6e90\u7684\u5229\u7528\u7531request, use, release\u4e09\u6b65\u7ec4\u6210\u3002 \u8d44\u6e90\u5206\u914d\u56fe\u662f\u4e00\u79cd\u6709\u5411\u56fe
\u6ca1\u6709\u73af\u4e00\u5b9a\u6ca1\u6709\u6b7b\u9501\uff0c\u6709\u73af\u53ef\u80fd\u4f46\u4e0d\u4e00\u5b9a\u6709\u6b7b\u9501\uff0c\u6709\u73af\u4e14\u6bcf\u4e2a\u8d44\u6e90\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u4e00\u5b9a\u6709\u6b7b\u9501\u3002
"},{"location":"CS/OS/process_syn/#72","title":"7.2 \u6b7b\u9501\u7684\u5fc5\u8981\u6761\u4ef6","text":"\ud83d\udca1 \u60f3\u8981\u7406\u89e3\u8fd9\u4e00\u5757\uff0c\u8bf7\u60f3\u8c61\u56db\u4e2a\u6210\u73af\u7684\u516c\u4ea4\u8def\u53e3\uff0c\u6bcf\u4e2a\u516c\u4ea4\u8def\u53e3\u90fd\u5835\u7740\u4e00\u6392\u60f3\u8981\u987a\u65f6\u9488\u524d\u884c\u7684\u8f66\u3002\u6bcf\u4e2a\u8f66\u90fd\u60f3\u8fdb\u5165\u4e0b\u4e00\u4e2a\u8def\u53e3\uff0c\u4f46\u662f\u6bcf\u4e2a\u8def\u53e3\u90fd\u88ab\u4e0a\u4e00\u8f86\u8f66\u5835\u7740\u4e0b\u9762\u56db\u70b9\u7684\u4ea4
\u5fc5\u8981\u6761\u4ef6\u2192\u6253\u7834\u4efb\u610f\u4e00\u70b9\u5c31\u80fd\u907f\u514d\u6b7b\u9501
\u5904\u7406\u6b7b\u9501\u7684\u56db\u79cd\u65b9\u6cd5
\u9884\u9632\u7684\u6838\u5fc3\u601d\u8def\u5c31\u662f\u6253\u7834\u5fc5\u8981\u6761\u4ef6\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u3002\u5206\u522b\u8ba8\u8bba\u56db\u4e2a\u6761\u4ef6\u5982\u4f55\u7834\u574f
\u907f\u514d\u6b7b\u9501\u5219\u662f\u9760\u9884\u6d4b\u8fdb\u7a0b\u672a\u6765\u9700\u8981\u4f7f\u7528\u54ea\u4e9b\u8d44\u6e90\u3001\u8d44\u6e90\u7684\u4f7f\u7528\u987a\u5e8f\u7b49\u3002\u7cfb\u7edf\u9700\u8981\u8bbe\u8ba1\u7b97\u6cd5\u8ba1\u7b97\u4e00\u4e0b\u6765\u907f\u514d\u3002\u6240\u4ee5\u65e2\u9700\u8981\u989d\u5916\u4fe1\u606f\uff0c\u53c8\u9700\u8981\u989d\u5916\u7b97\u6cd5\u3002
\u989d\u5916\u4fe1\u606f\u5305\u62ec
\u8d44\u6e90\u5206\u914d\u72b6\u6001resource allocation state:
\u8d44\u6e90\u5206\u914d\u56fe\u7b97\u6cd5\uff1a\u9002\u7528\u4e8e\u6bcf\u79cd\u8d44\u6e90\u90fd\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u7684\u60c5\u51b5
\u5728\u8d44\u6e90\u5206\u914d\u56fe\u4e0a\u52a0\u4e00\u79cd\u8fb9\uff1aclaim edge\u3002\u8868\u793a\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u9700\u8981\u67d0\u79cd\u8d44\u6e90\uff0c\u7528\u865a\u7ebf\u8868\u793a\u3002\u8f6c\u5316\u5173\u7cfb\u4e3a
graph TD\n claim_edge --\u9700\u6c42\u51fa\u73b0--> request_edge\n request_edge --\u4e0d\u4f1a\u51fa\u73b0\u73af\u7684\u8bdd\u5c31\u9700\u6c42\u6ee1\u8db3--> assignment_edge\n assignment_edge --\u8d44\u6e90\u91ca\u653e--> claim_edge\n
\u5b89\u5168\u72b6\u6001 Safe State
\u662f\u6307\u6309\u7167\u4e00\u5b9a\u987a\u5e8f\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u8d44\u6e90\uff0c\u540c\u65f6\u907f\u514d\u6b7b\u9501\u3002
\u5177\u4f53\u800c\u8a00\uff0c\u5982\u679c\u67d0\u4e2a\u8d44\u6e90\u6709A\u4e2a\u7a7a\u95f2\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u6d3b\u52a8\u8fdb\u7a0bPi\uff0c\u5404\u81ea\u6301\u6709Ci\u4e2a\u8be5\u8d44\u6e90\uff0c\u5e76\u4e14\u4ecd\u7136\u9700\u8981Di\u4e2a\u8d44\u6e90\u3002
\u5982\u679c\u4e00\u4e2a\u5e8f\u5217\u4f7f\u5f97\u5bf9\u4e8e\u4efb\u610fPi\uff0c\u90fd\u6709A+\\sum[j<i][j=1]{Ci} \u2265 Di, \u5219\u7cfb\u7edf\u5904\u4e8e\u5b89\u5168\u72b6\u6001\u3002
\u53ef\u4ee5\u7528\u5f52\u7eb3\u6cd5\u8bc1\u660e\uff1a\u5982\u679cPi\u7684\u9700\u6c42\u4e0d\u80fd\u88ab\u7acb\u523b\u6ee1\u8db3\uff0c\u53ea\u9700\u8981\u7b49\u5f85Pj | j<i \u5168\u90e8\u5b8c\u6210\u3002Pi\u5c31\u80fd\u83b7\u5f97\u6240\u9700\u8d44\u6e90 \u5b89\u5168\u72b6\u6001\u662f\u975e\u6b7b\u9501\u72b6\u6001\u7684\u5b50\u96c6
\u94f6\u884c\u5bb6\u7b97\u6cd5 Banker\u2019s Algorithm
\u901a\u8fc7available, max, allocation, need \u8fd9\u56db\u4e2a\u77e9\u9635\u523b\u753b\u4e00\u4e2a\u65f6\u95f4\u5185\u5404\u4e2a\u8fdb\u7a0b\u5bf9\u5404\u79cd\u8d44\u6e90\u7684\u6301\u6709\u548c\u9700\u6c42\u72b6\u51b5\uff0c\u4ee5\u53ca\u5f53\u524d\u7cfb\u7edf\u7684\u8d44\u6e90\u60c5\u51b5\u3002OS\u5e94\u4f7f\u7528\u8fd9\u4e9b\u6570\u636e\u5224\u65ad\u7cfb\u7edf\u662f\u5426\u5b89\u5168\u72b6\u6001\u3002
\u627e\u4e00\u4e2a\u5b89\u5168\u5e8f\u5217\u7684\u57fa\u672c\u601d\u8def\u662f\uff1a\u9009\u4e00\u4e2aneed\uff08\u7684\u6bcf\u4e00\u9879\u5bf9\u5e94\u5730\uff09\u5c0f\u4e8eavailable\uff08\u7684\u5bf9\u5e94\u9879\uff09\u7684\u8fdb\u7a0b\uff0c\u8fd0\u884c\u5b8c\u540e\u4f1a\u5c06allocation\u91ca\u653e\u56deavailable.
\u5047\u8bbe\u8fd9\u4e2a\u9700\u6c42\u88ab\u63a5\u53d7\u4e86\uff0c\u66f4\u65b0\u5bf9\u5e94\u7684need\uff0cavailable\uff0callocation
\u5728\u6b64\u72b6\u6001\u4e0b\u63a8\u6f14\u662f\u5426\u6709\u5408\u6cd5\u7684\u5b89\u5168\u5e8f\u5217\u3002
\u800c\u51b3\u5b9a\u4e00\u4e2a\u9700\u6c42\u662f\u5426\u5e94\u5f53\u88ab\u6ee1\u8db3\u7684\u65b9\u6848\u662f\uff0c\u5047\u8bbe\u88ab\u63a5\u53d7\u4e86\uff0c\u6839\u636e\u8be5\u9700\u6c42\u66f4\u65b0need\uff0cavailable\uff0callocation\uff0c\u5728\u6b64\u72b6\u6001\u63a8\u6f14\u662f\u5426\u6709\u5408\u6cd5\u7684\u5b89\u5168\u5e8f\u5217\u3002
"},{"location":"CS/OS/process_syn/#75","title":"7.5 \u68c0\u6d4b","text":"Single Instance Resources
wait-for graph\u6765\u89e3\u51b3
\u5728\u8fd9\u4e2a\u56fe\u91cc\u627e\u73af\uff0c\u7528\u62d3\u6251\u6392\u5e8f\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(V+E)\u7684\uff0c\u6700\u5dee\u60c5\u51b5\u4e0b\u662fO(n^2)\u7684\u3002 Multi-Instance Resources
\u7c7b\u4f3c\u94f6\u884c\u5bb6\u7b97\u6cd5\uff0c\u5982\u679c\u627e\u4e0d\u5230\u4efb\u4f55\u5b89\u5168\u5e8f\u5217\uff0c\u8bf4\u660e\u7cfb\u7edf\u5904\u4e8e\u6b7b\u9501\u3002
"},{"location":"CS/OS/process_syn/#76","title":"7.6 \u6062\u590d","text":"\u8fdb\u7a0b\u7ec8\u6b62Terminate deadlocked processes
\u5b83\u548c\u8d44\u6e90\u62a2\u5360\u7684\u533a\u522b\u4f3c\u4e4e\u662f\uff0c\u8fdb\u7a0b\u7ec8\u6b62\u4ee3\u4ef7\u975e\u5e38\u5927\uff0c\u5176\u4e00\u662f\u9700\u8981\u7ef4\u62a4\u7ec8\u6b62\u65f6\u7684\u72b6\u6001\uff0c\u5e76\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u4e00\u4e9b\u5185\u5bb9\uff0c\u5e76\u9700\u8981\u907f\u514d\u4ea7\u751f\u91cd\u590d\u7684\u526f\u4f5c\u7528\u3002
\u76f4\u63a5\u653e\u5f03\u6240\u6709\u8fdb\u7a0b\u82b1\u8d39\u4f1a\u5f88\u5927\u3002
\u53ef\u4ee5\u9009\u62e9\u6bcf\u6b21\u653e\u5f03\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u76f4\u5230\u6240\u6709\u6b7b\u9501\u73af\u89e3\u9664\u3002
\u5982\u4f55\u9009\u62e9\u653e\u5f03\u54ea\u4e2a\u8fdb\u7a0b\uff1a\u4e00\u7cfb\u5217\u6307\u6807
\u4e0d\u65ad\u62a2\u5360\u8d44\u6e90\u7ed9\u5176\u5b83\u8fdb\u7a0b\uff0c\u76f4\u5230\u6d88\u9664\u6b7b\u9501\u73af\u4e3a\u6b62
\u9700\u8981\u8003\u8651\u4e09\u4e2a\u95ee\u9898
\u672c\u7ae0\u8282\u5305\u62ec\u6df1\u5ea6\u5b66\u4e60\u7406\u8bba+\u5de5\u7a0b\u7b14\u8bb0\uff0c\u5df2\u5b8c\u6210\u4ee5\u4e0b\u5185\u5bb9 - \u5e38\u7528\u7684python\u547d\u4ee4 - \u5e38\u7528\u7684terminal\u547d\u4ee4 - NLP\u5b66\u4e60\u548c\u5de5\u7a0b\u7b14\u8bb0
"},{"location":"DL/NLPTech/bert_code/","title":"Note on BERT code","text":"Bert is an encoder-only Transformer structured model.
To implement a Bert, the following classes are required. - embedding: positional embedding, -
"},{"location":"DL/NLPTech/bert_code/#positional-embedding","title":"Positional Embedding","text":"class PositionalEmbedding(torch.nn.Module): \ndef __init__(self, d_model, max_len=128): \nsuper().__init__() \n# Compute the positional encodings once in log space. \npe = torch.zeros(max_len, d_model).float() \npe.require_grad = False \nfor pos in range(max_len): \n# for each dimension of the each position \nfor i in range(0, d_model, 2): \npe[pos, i] = math.sin(pos / (10000 ** ((2 * i)/d_model))) \npe[pos, i + 1] = math.cos(pos / (10000 ** ((2 * (i + 1))/d_model))) \n# include the batch size \nself.pe = pe.unsqueeze(0) \n# self.register_buffer('pe', pe) \ndef forward(self, x): \nreturn self.pe\n
"},{"location":"DL/NLPTech/bert_code/#bert-embedding","title":"Bert Embedding","text":"class BERTEmbedding(torch.nn.Module): \n\"\"\" \n BERT Embedding which is consisted with under features \n 1. TokenEmbedding : normal embedding matrix \n 2. PositionalEmbedding : adding positional information using sin, cos \n 2. SegmentEmbedding : adding sentence segment info, (sent_A:1, sent_B:2) \n sum of all these features are output of BERTEmbedding \n \"\"\" \ndef __init__(self, vocab_size, embed_size, seq_len=64, dropout=0.1): \n\"\"\" \n :param vocab_size: total vocab size \n :param embed_size: embedding size of token embedding \n :param dropout: dropout rate \n \"\"\" \nsuper().__init__() \nself.embed_size = embed_size \n# (m, seq_len) --> (m, seq_len, embed_size) \n# padding_idx is not updated during training, remains as fixed pad (0) \nself.token = torch.nn.Embedding(vocab_size, embed_size, padding_idx=0) \nself.segment = torch.nn.Embedding(3, embed_size, padding_idx=0) \nself.position = PositionalEmbedding(d_model=embed_size, max_len=seq_len) \nself.dropout = torch.nn.Dropout(p=dropout) \ndef forward(self, sequence, segment_label): \nx = self.token(sequence) + self.position(sequence) + self.segment(segment_label) \nreturn self.dropout(x)\n
"},{"location":"DL/NLPTech/bert_code/#multiheadattention","title":"MultiHeadAttention","text":"### attention layers \nclass MultiHeadedAttention(torch.nn.Module): \ndef __init__(self, heads, d_model, dropout=0.1): \nsuper(MultiHeadedAttention, self).__init__() \nassert d_model % heads == 0 \nself.d_k = d_model // heads \nself.heads = heads \nself.dropout = torch.nn.Dropout(dropout) \nself.query = torch.nn.Linear(d_model, d_model) \nself.key = torch.nn.Linear(d_model, d_model) \nself.value = torch.nn.Linear(d_model, d_model) \nself.output_linear = torch.nn.Linear(d_model, d_model) \ndef forward(self, query, key, value, mask): \n\"\"\" \n query, key, value of shape: (batch_size, max_len, d_model) \n mask of shape: (batch_size, 1, 1, max_words) \n \"\"\" \n# (batch_size, max_len, d_model) \nquery = self.query(query) \nkey = self.key(key) \nvalue = self.value(value) \n# (batch_size, max_len, d_model) --> (batch_size, max_len, h, d_k) --> (batch_size, h, max_len, d_k) \nquery = query.view(query.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \nkey = key.view(key.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \nvalue = value.view(value.shape[0], -1, self.heads, self.d_k).permute(0, 2, 1, 3) \n# (batch_size, h, max_len, d_k) matmul (batch_size, h, d_k, max_len) --> (batch_size, h, max_len, max_len) \nscores = torch.matmul(query, key.permute(0, 1, 3, 2)) / math.sqrt(query.size(-1)) \n# fill 0 mask with super small number so it wont affect the softmax weight \n# (batch_size, h, max_len, max_len) \nscores = scores.masked_fill(mask == 0, -1e9) \n# (batch_size, h, max_len, max_len) \n# softmax to put attention weight for all non-pad tokens \n# max_len X max_len matrix of attention \nweights = F.softmax(scores, dim=-1) \nweights = self.dropout(weights) \n# (batch_size, h, max_len, max_len) matmul (batch_size, h, max_len, d_k) --> (batch_size, h, max_len, d_k) \ncontext = torch.matmul(weights, value) \n# (batch_size, h, max_len, d_k) --> (batch_size, max_len, h, d_k) --> (batch_size, max_len, d_model) \ncontext = context.permute(0, 2, 1, 3).contiguous().view(context.shape[0], -1, self.heads * self.d_k) \n# (batch_size, max_len, d_model) \nreturn self.output_linear(context)\n
"},{"location":"DL/NLPTech/bert_code/#feedforward","title":"FeedForward","text":"class FeedForward(torch.nn.Module): \n\"Implements FFN equation.\" \ndef __init__(self, d_model, middle_dim=2048, dropout=0.1): \nsuper(FeedForward, self).__init__() \nself.fc1 = torch.nn.Linear(d_model, middle_dim) \nself.fc2 = torch.nn.Linear(middle_dim, d_model) \nself.dropout = torch.nn.Dropout(dropout) \nself.activation = torch.nn.GELU() \ndef forward(self, x): \nout = self.activation(self.fc1(x)) \nout = self.fc2(self.dropout(out)) \nreturn out \n
"},{"location":"DL/NLPTech/bert_code/#encoder-layer","title":"Encoder Layer","text":"class EncoderLayer(torch.nn.Module): \ndef __init__( \nself, \nd_model=768, \nheads=12, \nfeed_forward_hidden=768 * 4, \ndropout=0.1 \n): \nsuper(EncoderLayer, self).__init__() \nself.layernorm = torch.nn.LayerNorm(d_model) \nself.self_multihead = MultiHeadedAttention(heads, d_model) \nself.feed_forward = FeedForward(d_model, middle_dim=feed_forward_hidden) \nself.dropout = torch.nn.Dropout(dropout) \ndef forward(self, embeddings, mask): \n# embeddings: (batch_size, max_len, d_model) \n# encoder mask: (batch_size, 1, 1, max_len) \n# result: (batch_size, max_len, d_model) \ninteracted = self.dropout(self.self_multihead(embeddings, embeddings, embeddings, mask)) \n# residual layer \ninteracted = self.layernorm(interacted + embeddings) \n# bottleneck \nfeed_forward_out = self.dropout(self.feed_forward(interacted)) \nencoded = self.layernorm(feed_forward_out + interacted) \nreturn encoded\n
"},{"location":"DL/NLPTech/bert_code/#bert-model","title":"Bert model","text":"class BERT(torch.nn.Module): \n\"\"\" \n BERT model : Bidirectional Encoder Representations from Transformers. \n \"\"\" \ndef __init__(self, vocab_size, d_model=768, n_layers=12, heads=12, dropout=0.1): \n\"\"\" \n :param vocab_size: vocab_size of total words \n :param hidden: BERT model hidden size \n :param n_layers: numbers of Transformer blocks(layers) \n :param attn_heads: number of attention heads \n :param dropout: dropout rate \n \"\"\" \nsuper().__init__() \nself.d_model = d_model \nself.n_layers = n_layers \nself.heads = heads \n# paper noted they used 4 * hidden_size for ff_network_hidden_size \nself.feed_forward_hidden = d_model * 4 \n# embedding for BERT, sum of positional, segment, token embeddings \nself.embedding = BERTEmbedding(vocab_size=vocab_size, embed_size=d_model) \n# multi-layers transformer blocks, deep network \nself.encoder_blocks = torch.nn.ModuleList( \n[EncoderLayer(d_model, heads, d_model * 4, dropout) for _ in range(n_layers)]) \ndef forward(self, x, segment_info): \n# attention masking for padded token \n# (batch_size, 1, seq_len, seq_len) \nmask = (x > 0).unsqueeze(1).repeat(1, x.size(1), 1).unsqueeze(1) \n# embedding the indexed sequence to sequence of vectors \nx = self.embedding(x, segment_info) \n# running over multiple transformer blocks \nfor encoder in self.encoder_blocks: \nx = encoder.forward(x, mask) \nreturn x \nclass NextSentencePrediction(torch.nn.Module): \n\"\"\" \n 2-class classification model : is_next, is_not_next \n \"\"\" \ndef __init__(self, hidden): \n\"\"\" \n :param hidden: BERT model output size \n \"\"\" \nsuper().__init__() \nself.linear = torch.nn.Linear(hidden, 2) \nself.softmax = torch.nn.LogSoftmax(dim=-1) \ndef forward(self, x): \n# use only the first token which is the [CLS] \nreturn self.softmax(self.linear(x[:, 0])) \nclass MaskedLanguageModel(torch.nn.Module): \n\"\"\" \n predicting origin token from masked input sequence \n n-class classification problem, n-class = vocab_size \n \"\"\" \ndef __init__(self, hidden, vocab_size): \n\"\"\" \n :param hidden: output size of BERT model \n :param vocab_size: total vocab size \n \"\"\" \nsuper().__init__() \nself.linear = torch.nn.Linear(hidden, vocab_size) \nself.softmax = torch.nn.LogSoftmax(dim=-1) \ndef forward(self, x): \nreturn self.softmax(self.linear(x)) \n
class BERTLM(torch.nn.Module): \n\"\"\" \n BERT Language Model \n Next Sentence Prediction Model + Masked Language Model \n \"\"\" \ndef __init__(self, bert: BERT, vocab_size): \n\"\"\" \n :param bert: BERT model which should be trained \n :param vocab_size: total vocab size for masked_lm \n \"\"\" \nsuper().__init__() \nself.bert = bert \nself.next_sentence = NextSentencePrediction(self.bert.d_model) \nself.mask_lm = MaskedLanguageModel(self.bert.d_model, vocab_size) \ndef forward(self, x, segment_label): \nx = self.bert(x, segment_label) \nreturn self.next_sentence(x), self.mask_lm(x)\n
"},{"location":"DL/NLPTech/bert_code/#how-to-write-a-bert-trainer","title":"How to Write A BERT Trainer?","text":"In this section we will discuss how to train a BERT model. The loss function and optimizer are defined in the trainer as well.
criterion = nn.CrossEntropyLoss()\noptimizer = optim.Adam(model.parameters(), lr=0.001)\n
model = BERT()\nbatch = make_batch()\ninput_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(*batch))\n
for epoch in range(100):\n# initialize the parameters in optim with zero\noptimizer.zero_grad() \n# the arguments are input to the model\n# input_ids: \n# segment_ids:\n# masked pos:\nlogits_lm, logits_clsf = model(input_ids, segment_ids, masked_pos)\n# transpose to the masked_tokens' shape, and calculate the loss\nloss_lm = criterion(logits_lm.transpose(1, 2), masked_tokens) # for masked LM\n# calculate the average loss\nloss_lm = (loss_lm.float()).mean()\n# sentence classification loss\nloss_clsf = criterion(logits_clsf, isNext) # for sentence classification\nloss = loss_lm + loss_clsf\nif (epoch + 1) % 10 == 0:\nprint('Epoch:', '%04d' % (epoch + 1), 'cost =', '{:.6f}'.format(loss))\n# performs back propogation\nloss.backward()\n# the optimizer takes a step based on the computed gradients.\noptimizer.step()\n# Predict mask tokens\ninput_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(batch[0]))\nprint(text)\nprint([number_dict[w.item()] for w in input_ids[0] if number_dict[w.item()] != '[PAD]'])\nlogits_lm, logits_clsf = model(input_ids, segment_ids, masked_pos)\nlogits_lm = logits_lm.data.max(2)[1][0].data.numpy()\nprint('masked tokens list : ',[pos.item() for pos in masked_tokens[0] if pos.item() != 0])\nprint('predict masked tokens list : ',[pos for pos in logits_lm if pos != 0])\nlogits_clsf = logits_clsf.data.max(1)[1].data.numpy()[0]\nprint('isNext : ', True if isNext else False)\nprint('predict isNext : ',True if logits_clsf else False)\n
"},{"location":"DL/NLPTech/cs224n/","title":"CS224N \u7b14\u8bb0","text":"TODO
"},{"location":"DL/NLPTech/cs224n/#attention-based-nmt","title":"Attention-based NMT","text":""},{"location":"DL/NLPTech/cs224n/#convnet-based-nmt","title":"ConvNet-based NMT","text":""},{"location":"DL/NLPTech/cs224n/#final-project-implementing-a-model-to-challenge-sqaud","title":"Final project: implementing a model to challenge SQaUD","text":""},{"location":"DL/NLPTech/cs224n/#qanet","title":"QANet","text":""},{"location":"DL/NLPTech/cs231n/","title":"CS231n \u7b14\u8bb0","text":"TODO
"},{"location":"DL/NLPTech/cs231n/#pytorch","title":"Pytorch","text":"Output size calculation
output_size = (input_size + 2 * padding - kernel_size) / stride + 1\n
RuntimeError: mat2 must be a matrix, got 1-D tensor
torch.unsqueeze(fc_b, dim=1)\n
turns (10, ) list to (10, 1) tensor. "},{"location":"DL/NLPTech/cs231n/#self-supervised-learning","title":"Self-supervised Learning","text":""},{"location":"DL/NLPTech/cs231n/#gan","title":"GAN","text":""},{"location":"DL/NLPTech/cs231n/#transformer-image-caption","title":"Transformer Image Caption","text":""},{"location":"DL/NLPTech/gpt_code/","title":"Note on GPT code","text":"GPT's implementation involves only the decoder of the Transformer model.
class GPT(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.max_len = config.max_len\nself.tok_embed = nn.Embedding(\nconfig.vocab_size, embed_dim\n)\nself.pos_embed = nn.Parameter(\ntorch.zeros(1, config.max_len, embed_dim)\n)\nself.dropout = nn.Dropout(config.embed_dropout)\nself.blocks = nn.Sequential(\n*[DecoderBlock(config) for _ in range(config.num_blocks)]\n)\nself.ln = nn.LayerNorm(embed_dim)\nself.fc = nn.Linear(embed_dim, config.vocab_size)\ndef forward(self, x, target=None):\n# batch_size = x.size(0)\nseq_len = x.size(1)\nassert seq_len <= self.max_len, \"sequence longer than model capacity\"\ntok_embedding = self.tok_embed(x)\n# tok_embedding.shape == (batch_size, seq_len, embed_dim)\npos_embedding = self.pos_embed[:, :seq_len, :]\n# pos_embedding.shape == (1, seq_len, embed_dim)\nx = self.dropout(tok_embedding + pos_embedding)\nx = self.blocks(x)\nx = self.ln(x)\nx = self.fc(x)\n# x.shape == (batch_size, seq_len, vocab_size)\nreturn x\n
class DecoderBlock(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.ln1 = nn.LayerNorm(embed_dim)\nself.ln2 = nn.LayerNorm(embed_dim)\nself.attn = MultiheadAttention(config)\nself.ff = nn.Sequential(\nnn.Linear(embed_dim, embed_dim * 4),\nnn.GELU(),\nnn.Linear(embed_dim * 4, embed_dim),\nnn.Dropout(config.ff_dropout),\n)\ndef forward(self, x):\nx = x + self.attn(self.ln1(x))\nx = x + self.ff(self.ln2(x))\nreturn x\n
class MultiheadAttention(nn.Module):\ndef __init__(self, config):\nsuper().__init__()\nembed_dim = config.embed_dim\nself.num_heads = config.num_heads\nassert embed_dim % self.num_heads == 0, \"invalid heads and embedding dimension configuration\"\nself.key = nn.Linear(embed_dim, embed_dim)\nself.value = nn.Linear(embed_dim, embed_dim)\nself.query = nn.Linear(embed_dim, embed_dim)\nself.proj = nn.Linear(embed_dim, embed_dim)\nself.attn_dropout = nn.Dropout(config.attn_dropout)\nself.proj_dropout = nn.Dropout(config.ff_dropout)\nself.register_buffer(\n\"mask\", \ntorch.tril(torch.ones(config.max_len, config.max_len))\n.unsqueeze(0).unsqueeze(0)\n)\ndef forward(self, x):\nbatch_size = x.size(0)\nseq_len = x.size(1)\n# x.shape == (batch_size, seq_len, embed_dim)\nk_t = self.key(x).reshape(batch_size, seq_len, self.num_heads, -1).permute(0, 2, 3, 1)\nv = self.value(x).reshape(batch_size, seq_len, self.num_heads, -1).transpose(1, 2)\nq = self.query(x).reshape(batch_size, seq_len, self.num_heads, -1).transpose(1, 2)\n# shape == (batch_size, num_heads, seq_len, head_dim)\nattn = torch.matmul(q, k_t) / math.sqrt(q.size(-1))\n# attn.shape == (batch_size, num_heads, seq_len, seq_len)\nmask = self.mask[:, :, :seq_len, :seq_len]\nattn = attn.masked_fill(mask == 0, float(\"-inf\"))\nattn = self.attn_dropout(attn)\n# attn.shape == (batch_size, num_heads, seq_len, seq_len)\nattn = F.softmax(attn, dim=-1)\ny = torch.matmul(attn, v)\n# y.shape == (batch_size, num_heads, seq_len, head_dim)\ny = y.transpose(1, 2)\n# y.shape == (batch_size, seq_len, num_heads, head_dim)\ny = y.reshape(batch_size, seq_len, -1)\n# y.shape == (batch_size, seq_len, embed_dim)\ny = self.proj_dropout(self.proj(y))\nreturn y\n
Finally we will see its default configuration.
class GPTConfig:\nattn_dropout = 0.1\nembed_dropout = 0.1\nff_dropout = 0.1\ndef __init__(\nself, vocab_size, max_len, **kwargs\n):\nself.vocab_size = vocab_size\nself.max_len = max_len\nfor key, value in kwargs.items():\nsetattr(self, key, value)\nclass GPT1Config(GPTConfig):\nnum_heads = 12\nnum_blocks = 12\nembed_dim = 768\n
"},{"location":"DL/NLPTech/llama_code/","title":"Note on LLaMa Code","text":""},{"location":"DL/NLPTech/llama_code/#introduction","title":"Introduction","text":"This note only focuses on the classes and eliminates all other packages or data processing lines.
LLaMA is a decoder-only Transformer architecture. To implement a LLaMA, the following modules will be applied. - class LLaMA: generation - model utils: RMSNorm, Attention, FeedForward, TransformerBlock, Transformer
LLaMA makes 3 main improvements to the Transformer architecture: RMSNorm, RoPE, and SwiGLU.
"},{"location":"DL/NLPTech/llama_code/#rmsnorm","title":"RMSNorm","text":"Root mean square layer norm, proposed in 2019. Its capability in handling re-centering (removing mean) and re-scaling (maintaining square) of both inputs and weight matrix can stabilize training and boost model convergence. The RMSNorm only focuses on re-scaling invariance and regularizes the summed inputs according to the root mean square statistics. $$ \\bar{a_i} = \\frac{a_i}{RMS(a)}g_i, \\space where \\space RMS(a) = \\sqrt{\\frac{1}{n}\\sum_{i=1}^{n}{a^2_i}} $$
class RMSNorm(torch.nn.Module):\ndef __init__(self, dim: int, eps: float = 1e-6):\nsuper().__init__()\nself.eps = eps\nself.weight = nn.Parameter(torch.ones(dim))\ndef _norm(self, x):\nreturn x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)\ndef forward(self, x):\noutput = self._norm(x.float()).type_as(x)\nreturn output * self.weight\n
"},{"location":"DL/NLPTech/llama_code/#attention","title":"Attention","text":"def reshape_for_broadcast(freqs_cis: torch.Tensor, x: torch.Tensor):\nndim = x.ndim\nassert 0 <= 1 < ndim\nassert freqs_cis.shape == (x.shape[1], x.shape[-1])\nshape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]\nreturn freqs_cis.view(*shape)\n
def apply_rotary_emb(\nxq: torch.Tensor,\nxk: torch.Tensor,\nfreqs_cis: torch.Tensor,\n) -> Tuple[torch.Tensor, torch.Tensor]:\nxq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))\nxk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))\nfreqs_cis = reshape_for_broadcast(freqs_cis, xq_)\nxq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3)\nxk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3)\nreturn xq_out.type_as(xq), xk_out.type_as(xk)\n
def repeat_kv(x: torch.Tensor, n_rep: int) -> torch.Tensor:\n\"\"\"torch.repeat_interleave(x, dim=2, repeats=n_rep)\"\"\"\nbs, slen, n_kv_heads, head_dim = x.shape\nif n_rep == 1:\nreturn x\nreturn (\nx[:, :, :, None, :]\n.expand(bs, slen, n_kv_heads, n_rep, head_dim)\n.reshape(bs, slen, n_kv_heads * n_rep, head_dim)\n)\n
class Attention(nn.Module):\ndef __init__(self, args: ModelArgs):\nsuper().__init__()\nself.n_kv_heads = args.n_heads if args.n_kv_heads is None else args.n_kv_heads\nmodel_parallel_size = fs_init.get_model_parallel_world_size()\nself.n_local_heads = args.n_heads // model_parallel_size\nself.n_local_kv_heads = self.n_kv_heads // model_parallel_size\nself.n_rep = self.n_local_heads // self.n_local_kv_heads\nself.head_dim = args.dim // args.n_heads\nself.wq = ColumnParallelLinear(\nargs.dim,\nargs.n_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wk = ColumnParallelLinear(\nargs.dim,\nself.n_kv_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wv = ColumnParallelLinear(\nargs.dim,\nself.n_kv_heads * self.head_dim,\nbias=False,\ngather_output=False,\ninit_method=lambda x: x,\n)\nself.wo = RowParallelLinear(\nargs.n_heads * self.head_dim,\nargs.dim,\nbias=False,\ninput_is_parallel=True,\ninit_method=lambda x: x,\n)\nself.cache_k = torch.zeros(\n(\nargs.max_batch_size,\nargs.max_seq_len,\nself.n_local_kv_heads,\nself.head_dim,\n)\n).cuda()\nself.cache_v = torch.zeros(\n(\nargs.max_batch_size,\nargs.max_seq_len,\nself.n_local_kv_heads,\nself.head_dim,\n)\n).cuda()\ndef forward(\nself,\nx: torch.Tensor,\nstart_pos: int,\nfreqs_cis: torch.Tensor,\nmask: Optional[torch.Tensor],\n):\nbsz, seqlen, _ = x.shape\nxq, xk, xv = self.wq(x), self.wk(x), self.wv(x)\nxq = xq.view(bsz, seqlen, self.n_local_heads, self.head_dim)\nxk = xk.view(bsz, seqlen, self.n_local_kv_heads, self.head_dim)\nxv = xv.view(bsz, seqlen, self.n_local_kv_heads, self.head_dim)\nxq, xk = apply_rotary_emb(xq, xk, freqs_cis=freqs_cis)\nself.cache_k = self.cache_k.to(xq)\nself.cache_v = self.cache_v.to(xq)\nself.cache_k[:bsz, start_pos : start_pos + seqlen] = xk\nself.cache_v[:bsz, start_pos : start_pos + seqlen] = xv\nkeys = self.cache_k[:bsz, : start_pos + seqlen]\nvalues = self.cache_v[:bsz, : start_pos + seqlen]\n# repeat k/v heads if n_kv_heads < n_heads\nkeys = repeat_kv(keys, self.n_rep) # (bs, seqlen, n_local_heads, head_dim)\nvalues = repeat_kv(values, self.n_rep) # (bs, seqlen, n_local_heads, head_dim)\nxq = xq.transpose(1, 2) # (bs, n_local_heads, seqlen, head_dim)\nkeys = keys.transpose(1, 2)\nvalues = values.transpose(1, 2)\nscores = torch.matmul(xq, keys.transpose(2, 3)) / math.sqrt(self.head_dim)\nif mask is not None:\nscores = scores + mask # (bs, n_local_heads, seqlen, cache_len + seqlen)\nscores = F.softmax(scores.float(), dim=-1).type_as(xq)\noutput = torch.matmul(scores, values) # (bs, n_local_heads, seqlen, head_dim)\noutput = output.transpose(1, 2).contiguous().view(bsz, seqlen, -1)\nreturn self.wo(output)\n
"},{"location":"DL/NLPTech/llama_code/#feedforward","title":"FeedForward","text":"class FeedForward(nn.Module):\ndef __init__(\nself,\ndim: int,\nhidden_dim: int,\nmultiple_of: int,\nffn_dim_multiplier: Optional[float],\n):\nsuper().__init__()\nhidden_dim = int(2 * hidden_dim / 3)\n# custom dim factor multiplier\nif ffn_dim_multiplier is not None:\nhidden_dim = int(ffn_dim_multiplier * hidden_dim)\nhidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)\nself.w1 = ColumnParallelLinear(\ndim, hidden_dim, bias=False, gather_output=False, init_method=lambda x: x\n)\nself.w2 = RowParallelLinear(\nhidden_dim, dim, bias=False, input_is_parallel=True, init_method=lambda x: x\n)\nself.w3 = ColumnParallelLinear(\ndim, hidden_dim, bias=False, gather_output=False, init_method=lambda x: x\n)\ndef forward(self, x):\nreturn self.w2(F.silu(self.w1(x)) * self.w3(x))\n
"},{"location":"DL/NLPTech/llama_code/#transformerblock","title":"TransformerBlock","text":"class TransformerBlock(nn.Module):\ndef __init__(self, layer_id: int, args: ModelArgs):\nsuper().__init__()\nself.n_heads = args.n_heads\nself.dim = args.dim\nself.head_dim = args.dim // args.n_heads\nself.attention = Attention(args)\nself.feed_forward = FeedForward(\ndim=args.dim,\nhidden_dim=4 * args.dim,\nmultiple_of=args.multiple_of,\nffn_dim_multiplier=args.ffn_dim_multiplier,\n)\nself.layer_id = layer_id\nself.attention_norm = RMSNorm(args.dim, eps=args.norm_eps)\nself.ffn_norm = RMSNorm(args.dim, eps=args.norm_eps)\ndef forward(\nself,\nx: torch.Tensor,\nstart_pos: int,\nfreqs_cis: torch.Tensor,\nmask: Optional[torch.Tensor],\n):\n# Add & Norm. add an highway to the attention block.\nh = x + self.attention.forward(\nself.attention_norm(x), start_pos, freqs_cis, mask\n)\n# feedforward and addition\nout = h + self.feed_forward.forward(self.ffn_norm(h))\nreturn out\n
"},{"location":"DL/NLPTech/llama_code/#transformer","title":"Transformer","text":"We implement several utility functions before implementing the transformer model.
def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0):\nfreqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))\nt = torch.arange(end, device=freqs.device) # type: ignore\nfreqs = torch.outer(t, freqs).float() # type: ignore\nfreqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64\nreturn freqs_cis\n
class Transformer(nn.Module):\ndef __init__(self, params: ModelArgs):\nsuper().__init__()\nself.params = params\nself.vocab_size = params.vocab_size\nself.n_layers = params.n_layers\nself.tok_embeddings = ParallelEmbedding(\nparams.vocab_size, params.dim, init_method=lambda x: x\n)\nself.layers = torch.nn.ModuleList()\nfor layer_id in range(params.n_layers):\nself.layers.append(TransformerBlock(layer_id, params))\nself.norm = RMSNorm(params.dim, eps=params.norm_eps)\nself.output = ColumnParallelLinear(\nparams.dim, params.vocab_size, bias=False, init_method=lambda x: x\n)\nself.freqs_cis = precompute_freqs_cis(\nself.params.dim // self.params.n_heads, self.params.max_seq_len * 2\n)\n@torch.inference_mode()\ndef forward(self, tokens: torch.Tensor, start_pos: int):\n_bsz, seqlen = tokens.shape\nh = self.tok_embeddings(tokens)\nself.freqs_cis = self.freqs_cis.to(h.device)\nfreqs_cis = self.freqs_cis[start_pos : start_pos + seqlen]\nmask = None\nif seqlen > 1:\nmask = torch.full(\n(1, 1, seqlen, seqlen), float(\"-inf\"), device=tokens.device\n)\nmask = torch.triu(mask, diagonal=start_pos + 1).type_as(h)\nfor layer in self.layers:\nh = layer(h, start_pos, freqs_cis, mask)\nh = self.norm(h)\noutput = self.output(h).float()\nreturn output\n
"},{"location":"DL/NLPTech/llama_code/#llama","title":"LLaMa","text":"Let's finally see the default model args.
@dataclass\nclass ModelArgs:\ndim: int = 4096\nn_layers: int = 32\nn_heads: int = 32\nn_kv_heads: Optional[int] = None\nvocab_size: int = -1 # defined later by tokenizer\nmultiple_of: int = 256 # make SwiGLU hidden layer size multiple of large power of 2\nffn_dim_multiplier: Optional[float] = None\nnorm_eps: float = 1e-5\nmax_batch_size: int = 32\nmax_seq_len: int = 2048\n
class Llama:\n@staticmethod\ndef build(\nckpt_dir: str,\ntokenizer_path: str,\nmax_seq_len: int,\nmax_batch_size: int,\nmodel_parallel_size: Optional[int] = None,\n) -> \"Llama\":\nif not torch.distributed.is_initialized():\ntorch.distributed.init_process_group(\"nccl\")\nif not model_parallel_is_initialized():\nif model_parallel_size is None:\nmodel_parallel_size = int(os.environ.get(\"WORLD_SIZE\", 1))\ninitialize_model_parallel(model_parallel_size)\nlocal_rank = int(os.environ.get(\"LOCAL_RANK\", 0))\ntorch.cuda.set_device(local_rank)\n# seed must be the same in all processes\ntorch.manual_seed(1)\nif local_rank > 0:\nsys.stdout = open(os.devnull, \"w\")\nstart_time = time.time()\ncheckpoints = sorted(Path(ckpt_dir).glob(\"*.pth\"))\nassert len(checkpoints) > 0, f\"no checkpoint files found in {ckpt_dir}\"\nassert model_parallel_size == len(\ncheckpoints\n), f\"Loading a checkpoint for MP={len(checkpoints)} but world size is {model_parallel_size}\"\nckpt_path = checkpoints[get_model_parallel_rank()]\ncheckpoint = torch.load(ckpt_path, map_location=\"cpu\")\nwith open(Path(ckpt_dir) / \"params.json\", \"r\") as f:\nparams = json.loads(f.read())\nmodel_args: ModelArgs = ModelArgs(\nmax_seq_len=max_seq_len,\nmax_batch_size=max_batch_size,\n**params,\n)\ntokenizer = Tokenizer(model_path=tokenizer_path)\nmodel_args.vocab_size = tokenizer.n_words\ntorch.set_default_tensor_type(torch.cuda.HalfTensor)\nmodel = Transformer(model_args)\nmodel.load_state_dict(checkpoint, strict=False)\nprint(f\"Loaded in {time.time() - start_time:.2f} seconds\")\nreturn Llama(model, tokenizer)\ndef __init__(self, model: Transformer, tokenizer: Tokenizer):\nself.model = model\nself.tokenizer = tokenizer\n@torch.inference_mode()\ndef generate(\nself,\nprompt_tokens: List[List[int]],\nmax_gen_len: int,\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nlogprobs: bool = False,\necho: bool = False,\n) -> Tuple[List[List[int]], Optional[List[List[float]]]]:\nparams = self.model.params\nbsz = len(prompt_tokens)\nassert bsz <= params.max_batch_size, (bsz, params.max_batch_size)\nmin_prompt_len = min(len(t) for t in prompt_tokens)\nmax_prompt_len = max(len(t) for t in prompt_tokens)\nassert max_prompt_len <= params.max_seq_len\ntotal_len = min(params.max_seq_len, max_gen_len + max_prompt_len)\npad_id = self.tokenizer.pad_id\ntokens = torch.full((bsz, total_len), pad_id, dtype=torch.long, device=\"cuda\")\nfor k, t in enumerate(prompt_tokens):\ntokens[k, : len(t)] = torch.tensor(t, dtype=torch.long, device=\"cuda\")\nif logprobs:\ntoken_logprobs = torch.zeros_like(tokens, dtype=torch.float)\nprev_pos = 0\neos_reached = torch.tensor([False] * bsz, device=\"cuda\")\ninput_text_mask = tokens != pad_id\nfor cur_pos in range(min_prompt_len, total_len):\nlogits = self.model.forward(tokens[:, prev_pos:cur_pos], prev_pos)\nif logprobs:\ntoken_logprobs[:, prev_pos + 1 : cur_pos + 1] = -F.cross_entropy(\ninput=logits.transpose(1, 2),\ntarget=tokens[:, prev_pos + 1 : cur_pos + 1],\nreduction=\"none\",\nignore_index=pad_id,\n)\nif temperature > 0:\nprobs = torch.softmax(logits[:, -1] / temperature, dim=-1)\nnext_token = sample_top_p(probs, top_p)\nelse:\nnext_token = torch.argmax(logits[:, -1], dim=-1)\nnext_token = next_token.reshape(-1)\n# only replace token if prompt has already been generated\nnext_token = torch.where(\ninput_text_mask[:, cur_pos], tokens[:, cur_pos], next_token\n)\ntokens[:, cur_pos] = next_token\neos_reached |= (~input_text_mask[:, cur_pos]) & (\nnext_token == self.tokenizer.eos_id\n)\nprev_pos = cur_pos\nif all(eos_reached):\nbreak\nif logprobs:\ntoken_logprobs = token_logprobs.tolist()\nout_tokens, out_logprobs = [], []\nfor i, toks in enumerate(tokens.tolist()):\n# cut to max gen len\nstart = 0 if echo else len(prompt_tokens[i])\ntoks = toks[start : len(prompt_tokens[i]) + max_gen_len]\nprobs = None\nif logprobs:\nprobs = token_logprobs[i][start : len(prompt_tokens[i]) + max_gen_len]\n# cut to eos tok if any\nif self.tokenizer.eos_id in toks:\neos_idx = toks.index(self.tokenizer.eos_id)\ntoks = toks[:eos_idx]\nprobs = probs[:eos_idx] if logprobs else None\nout_tokens.append(toks)\nout_logprobs.append(probs)\nreturn (out_tokens, out_logprobs if logprobs else None)\ndef text_completion(\nself,\nprompts: List[str],\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nmax_gen_len: Optional[int] = None,\nlogprobs: bool = False,\necho: bool = False,\n) -> List[CompletionPrediction]:\nif max_gen_len is None:\nmax_gen_len = self.model.params.max_seq_len - 1\nprompt_tokens = [self.tokenizer.encode(x, bos=True, eos=False) for x in prompts]\ngeneration_tokens, generation_logprobs = self.generate(\nprompt_tokens=prompt_tokens,\nmax_gen_len=max_gen_len,\ntemperature=temperature,\ntop_p=top_p,\nlogprobs=logprobs,\necho=echo,\n)\nif logprobs:\nreturn [\n{\n\"generation\": self.tokenizer.decode(t),\n\"tokens\": [self.tokenizer.decode(x) for x in t],\n\"logprobs\": logprobs_i,\n}\nfor t, logprobs_i in zip(generation_tokens, generation_logprobs)\n]\nreturn [{\"generation\": self.tokenizer.decode(t)} for t in generation_tokens]\ndef chat_completion(\nself,\ndialogs: List[Dialog],\ntemperature: float = 0.6,\ntop_p: float = 0.9,\nmax_gen_len: Optional[int] = None,\nlogprobs: bool = False,\n) -> List[ChatPrediction]:\nif max_gen_len is None:\nmax_gen_len = self.model.params.max_seq_len - 1\nprompt_tokens = []\nunsafe_requests = []\nfor dialog in dialogs:\nunsafe_requests.append(\nany([tag in msg[\"content\"] for tag in SPECIAL_TAGS for msg in dialog])\n)\nif dialog[0][\"role\"] == \"system\":\ndialog = [\n{\n\"role\": dialog[1][\"role\"],\n\"content\": B_SYS\n+ dialog[0][\"content\"]\n+ E_SYS\n+ dialog[1][\"content\"],\n}\n] + dialog[2:]\nassert all([msg[\"role\"] == \"user\" for msg in dialog[::2]]) and all(\n[msg[\"role\"] == \"assistant\" for msg in dialog[1::2]]\n), (\n\"model only supports 'system', 'user' and 'assistant' roles, \"\n\"starting with 'system', then 'user' and alternating (u/a/u/a/u...)\"\n)\ndialog_tokens: List[int] = sum(\n[\nself.tokenizer.encode(\nf\"{B_INST} {(prompt['content']).strip()} {E_INST} {(answer['content']).strip()} \",\nbos=True,\neos=True,\n)\nfor prompt, answer in zip(\ndialog[::2],\ndialog[1::2],\n)\n],\n[],\n)\nassert (\ndialog[-1][\"role\"] == \"user\"\n), f\"Last message must be from user, got {dialog[-1]['role']}\"\ndialog_tokens += self.tokenizer.encode(\nf\"{B_INST} {(dialog[-1]['content']).strip()} {E_INST}\",\nbos=True,\neos=False,\n)\nprompt_tokens.append(dialog_tokens)\ngeneration_tokens, generation_logprobs = self.generate(\nprompt_tokens=prompt_tokens,\nmax_gen_len=max_gen_len,\ntemperature=temperature,\ntop_p=top_p,\nlogprobs=logprobs,\n)\nif logprobs:\nreturn [\n{\n\"generation\": {\n\"role\": \"assistant\",\n\"content\": self.tokenizer.decode(t)\nif not unsafe\nelse UNSAFE_ERROR,\n},\n\"tokens\": [self.tokenizer.decode(x) for x in t],\n\"logprobs\": logprobs_i,\n}\nfor t, logprobs_i, unsafe in zip(\ngeneration_tokens, generation_logprobs, unsafe_requests\n)\n]\nreturn [\n{\n\"generation\": {\n\"role\": \"assistant\",\n\"content\": self.tokenizer.decode(t) if not unsafe else UNSAFE_ERROR,\n}\n}\nfor t, unsafe in zip(generation_tokens, unsafe_requests)\n]\ndef sample_top_p(probs, p):\nprobs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)\nprobs_sum = torch.cumsum(probs_sort, dim=-1)\nmask = probs_sum - probs_sort > p\nprobs_sort[mask] = 0.0\nprobs_sort.div_(probs_sort.sum(dim=-1, keepdim=True))\nnext_token = torch.multinomial(probs_sort, num_samples=1)\nnext_token = torch.gather(probs_idx, -1, next_token)\nreturn next_token\n
"},{"location":"DL/NLPTech/llama_code/#references","title":"References","text":"facebookresearch/llama: Inference code for LLaMA models (github.com)
"},{"location":"DL/NLPTech/ml_cheatsheet/","title":"ML\u516b\u80a1 ero to hero","text":""},{"location":"DL/NLPTech/ml_cheatsheet/#ml","title":"ML","text":"\u8bbe\u8ba1\u6a21\u578b\u7684\u65f6\u5019\uff0c\u5982\u4f55\u786e\u5b9aembedding\u7684size? embedding\u7684\u5927\u5c0f\u4e00\u822c\u662f\u4e00\u4e2a\u7ecf\u9a8c\u503c\uff0c\u5047\u8bbeembedding\u5bf9\u5e94\u7684\u539f\u59cbfeature\u7684\u53d6\u503c\u6570\u91cf\u4e3an\uff0c\u5219\u4e00\u822c\u4f1a\u91c7\u7528\\(log_2(n)\\)\u6216\u8005\\(k\\sqrt[4]{n} (k<16)\\)\u6765\u505a\u521d\u59cb\u7684size\uff0c\u7136\u540e2\u500d\u6269\u5927\u6216\u7f29\u5c0f\u3002
Self Attention\u7684\u8868\u8fbe\u5f0f \\(\\(Softmax(\\frac{QK^T}{\\sqrt{d_k}})V\\)\\) \u5bf9QK\u8fdb\u884cscaling\u7684\u76ee\u7684\u662f\uff0cscaling\u540e\u8fdb\u884csoftmax\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u53d8\u5f97\u66f4\u597d\u3002\u6570\u503c\u4f1a\u8fdb\u5165\u654f\u611f\u533a\u95f4\uff0c\u9632\u6b62\u68af\u5ea6\u6d88\u5931\uff0c\u8ba9\u6a21\u578b\u66f4\u5bb9\u6613\u8bad\u7ec3\u3002
attention\u8ba1\u7b97\u65b9\u5f0f\u53ca\u53c2\u6570\u91cf\uff1f\u9ed8\u5199multi-headed attention? \u7b80\u7ea6\u7248
import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport math\nclass MultiHeadAttention(nn.Module):\ndef __init__(self, d_model, num_heads):\nsuper(MultiHeadAttention, self).__init__()\nself.num_heads = num_heads\nself.d_model = d_model # d_model is a emphirical number\nassert d_model % self.num_heads == 0\n# define the dimension of each head or subspace\nself.d_k = d_model // self.num_heads\n# these are still of dimension d_model. They will be split into numbers\nself.W_q = nn.Linear(d_model, d_model)\nself.W_k = nn.Linear(d_model, d_model)\nself.W_v = nn.Linear(d_model, d_model)\n# Output of all sub-layers need to be of dimension d_model\nself.W_o = nn.Linear(d_model, d_model)\ndef scaled_dot_product_attention(self, Q, K, V, mask = None):\nbatch_size = Q.size(0) # layernorm?\nK_length = K.size(-2) # \n# scaling by d_k so that the soft(arg)max doesn't explode\nQK = torch.matmul(Q, K.transpose(-2, -1) / math.sqrt(self.d_k))# matrix product of tensors\n# apply the mask\nif mask is not None: # mask is a matrix with 0 to be masked\nQK = QK.maksed_fill(mask.to(QK.type) == 0, float('-inf'))\n# calculate the attention weights (softmax over the lask dimension)\nweights = F.softmax(QK, dim = -1)\n# apply the self attention to the values\nattention = torch.matmul(weights, V)\nreturn attention, weights\ndef split_heads(self, x, batch_size):\n\"\"\"\n The original tensor \n with dimension batch_size * seq_length * d_model is divided by num_heads\n d_model // num_heads = d_k\n so now batch_size * seq_length * d_k\n \"\"\"\nreturn x.view(batch_size, -1, self.num_heads, self.d_k).transpose(1, 2)\ndef forward(self, q, k, v, mask = None):\nbatch_size = q.size(0)\n# linear layers\nq = self.W_q(q)\nk = self.W_k(k)\nv = self.W_v(v)\n# split into multiple heads\nq = self.split_heads(q, batch_size)\nk = self.split_heads(k, batch_size)\nv = self.split_heads(v, batch_size)\n# self attention\nscores, weights = self.scaled_dot_product_attention(q, k, v, mask)\n# concatenate heads\nconcat = scores.transpose(1, 2).contiguous().view(batch_size, -1, self.d_model())\n# final linear layer\noutput = self.W_o(concat)\nreturn output, weights\n
Multi-headed attention \u5f97\u5230\u7684\u662f\u4e24\u4e2a\u8f93\u51fa\uff0c\u4e00\u4e2aoutput\uff081 * d_model\uff09\u662f\u7ebf\u6027\u7684attention\u7ed3\u679c\uff0c\u4e00\u4e2aweight\u77e9\u9635\u662f\uff1f\u7ef4\u7684. \u51fa\u4e8e\u8fd0\u7b97\u901f\u5ea6\u7684\u8003\u8651\uff0c\u6211\u4eec\u8ba4\u4e3a\u201c\u4e00\u6b21\u5927\u7684\u77e9\u9635\u4e58\u6cd5\u7684\u6267\u884c\u901f\u5ea6\u6bd4\u591a\u6b21\u8f83\u5c0f\u7684\u77e9\u9635\u4e58\u6cd5\u66f4\u5feb\u201d\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728__init__\u4e2d self.qkv = nn.Linear(d_model, 3 * d_model)\n
\u5728forward\u65b9\u6cd5\u4e2d qkv = self.qkv(x)\nq, k, v = torch.split(qkv, self.d_model, dim = -1) # split into three tensors\n
Lora\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\uff1f \uff081\uff09\u57fa\u4e8e\u4f4e\u79e9\u7684\u5fae\u8c03\u53ef\u80fd\u4e0dalways work\uff0c\u6bd4\u5982finetune\u4e0epretrain\u4efb\u52a1\u7684gap\u8fc7\u5927\u7684\u65f6\u5019\uff08\u5982\uff1a\u4e2d\u82f1\u5dee\u5f02\uff09\u3002\u5f53\u7136\u8fd9\u4e00\u70b9\u5728LLM\u65f6\u4ee3\u53ef\u80fd\u5e76\u4e0d\u7a81\u51fa\uff0c\u56e0\u4e3a\u6211\u4eec\u8ba4\u4e3aLLM\u5728\u4e0e\u8bad\u7ec3\u9636\u6bb5\u5df2\u7ecfget\u4e86\u57fa\u672c\u6240\u6709\u7684\u77e5\u8bc6\uff0cfinetune\u4e5f\u53ea\u662f\u5728\u5fae\u8c03\u683c\u5f0f\uff0c\u56e0\u6b64\u53ef\u80fd\u4e0d\u4f1a\u6709\u4e0a\u8ff0gap\u8fc7\u5927\u7684\u60c5\u51b5\u3002 \uff082\uff09\u7528LoRA\u65f6\u4e5f\u8981\u8bbe\u7f6er\u548ctarget module\u7b49\uff0c\u8fd9\u90e8\u5206\u8d85\u53c2\u7684\u8bbe\u7f6e\u9700\u8981\u8003\u8651\u3002
\u5404\u79cdnorm\u65b9\u5f0f\u7684\u4f18\u7f3a\u70b9 \u5e38\u89c1\u7684norm\u65b9\u5f0f\u6709\u4ee5\u4e0b\u56db\u79cd\uff1a Batch norm: \u628a\u6bcf\u4e2abatch\u4e2d\u6bcf\u53e5\u8bdd\u76f8\u540c\u4f4d\u7f6e\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002\u5728\u5904\u7406\u5e8f\u5217\u6570\u636e\uff08\u5982\u6587\u672c\uff09\u65f6\uff0cbatch norm\u53ef\u80fd\u4e0d\u4f1a\u8868\u73b0\u5f88\u597d\uff0c\u56e0\u4e3a\u5e8f\u5217\u6570\u636e\u901a\u5e38\u957f\u5ea6\u4e0d\u4e00\uff0c\u5e76\u4e14\u4e00\u6b21\u8bad\u7ec3\u4e2dbatch\u7684\u53e5\u5b50\u957f\u5ea6\u53ef\u80fd\u4f1a\u6709\u5f88\u5927\u7684\u5dee\u5f02\uff0c\u6b64\u5916\uff0cbatch norm\u5bf9batch\u7684\u5927\u5c0f\u4e5f\u975e\u5e38\u654f\u611f\uff0c\u5bf9\u4e8e\u8f83\u5c0f\u7684batch\u5927\u5c0f\uff0cbatch norm\u53ef\u80fd\u4e5f\u4f1a\u8868\u73b0\u4e0d\u597d\uff0c\u56e0\u4e3a\u6bcf\u4e2abatch\u7684\u7edf\u8ba1\u7279\u6027\u53ef\u80fd\u4f1a\u6709\u8f83\u5927\u6ce2\u52a8\u3002
Layer norm: \u5728\u6bcf\u4e2a\u53e5\u5b50\u4e2d\u8fdb\u884c\u5f52\u4e00\u5316\u3002Layer norm\u662f\u5bf9\u6bcf\u4e2a\u6837\u672c\u8fdb\u884c\u5f52\u4e00\u5316\uff0c\u56e0\u6b64\u5b83\u4eec\u5bf9batch\u5927\u5c0f\u4e0d\u654f\u611f\uff0c\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u5904\u7406\u5e8f\u5217\u6570\u636e\u7684\u65f6\u5019\u8868\u73b0\u5f97\u66f4\u597d\uff0c\u53e6\u5916layer norm\u5728\u5904\u7406\u4e0d\u540c\u957f\u5ea6\u7684\u5e8f\u5217\u65f6\u4e5f\u66f4\u7075\u6d3b\u3002
Instance norm: \u6bcf\u4e00\u4e2a\u5b57\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002\u4f18\u70b9\u662f\u5bf9\u6bcf\u4e2a\u6837\u672c\u7684\u6bcf\u4e2a\u7279\u5f81\u8fdb\u884c\u5f52\u4e00\u5316\uff0c\u56e0\u6b64\u53ef\u4ee5\u6355\u6349\u5230\u66f4\u591a\u7684\u7ec6\u8282\u4fe1\u606f\uff0c\u80fd\u5728\u98ce\u683c\u8fc1\u79fb\u4e2d\u8868\u73b0\u66f4\u597d\uff0c\u56e0\u4e3a\u5728\u8fd9\u4e9b\u4efb\u52a1\u4e2d\u7ec6\u8282\u5f88\u91cd\u8981\u3002\u7f3a\u70b9\u662f\u53ef\u80fd\u4f1a\u8fc7\u5ea6\u5f3a\u8c03\u7ec6\u8282\u4fe1\u606f\uff0c\u5ffd\u7565\u4e86\u66f4\u5b8f\u89c2\u7684\u4fe1\u606f\u3002\u6b64\u5916instance norm\u7684\u8ba1\u7b97\u6210\u672c\u76f8\u6bd4batch norm\u548clayer norm\u4e5f\u66f4\u9ad8\u3002
Group norm: \u628a\u6bcf\u53e5\u8bdd\u7684\u6bcf\u51e0\u4e2a\u5b57\u7684\u5b57\u5411\u91cf\u770b\u6210\u4e00\u7ec4\u505a\u5f52\u4e00\u5316\u3002group norm\u662fbatch norm\u548cinstance norm\u7684\u6298\u4e2d\u65b9\u6848\uff0c\u5728\u4e00\u4e2a\u5b50\u96c6\uff08\u5373\u7ec4\uff09\u4e0a\u8fdb\u884c\u5f52\u4e00\u5316\u3002\u8fd9\u4f7f\u5f97group norm\u65e2\u53ef\u4ee5\u6355\u6349\u5230batch\u7684\u7edf\u8ba1\u7279\u6027\uff0c\u53c8\u53ef\u4ee5\u6355\u6349\u5230\u6837\u672c\u7684\u7ec6\u8282\u4fe1\u606f\u3002\u6b64\u5916\uff0cgroup norm\u5bf9batch\u5927\u5c0f\u4e5f\u4e0d\u654f\u611f\u3002\u7f3a\u70b9\u662fgroup norm\u7684\u6027\u80fd\u53d6\u51b3\u4e8e\u7ec4\u7684\u5927\u5c0f\uff0c\u9700\u8981\u901a\u8fc7\u5b9e\u9a8c\u786e\u5b9a\u6700\u4f18\u7ec4\u7684\u5927\u5c0f\u3002\u6b64\u5916group norm\u7684\u8ba1\u7b97\u6210\u672c\u4e5f\u6bd4batch norm\u548clayer norm\u66f4\u9ad8\u3002
Gradient Clipping RNN\u53ef\u80fd\u9047\u5230\u68af\u5ea6\u7206\u70b8\u95ee\u9898\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5982\u679c\u68af\u5ea6\u53d8\u5f97\u5f88\u5927\uff0c\u6211\u4eec\u5c06\u68af\u5ea6\u653e\u7f29\u4f7f\u5176\u53d8\u5c0f\u3002 \u7b97\u6cd5\u662f\uff1a\u5f53\u68af\u5ea6\u5927\u4e8e\u4e00\u4e2a\u5e38\u6570c\u7684\u65f6\u5019\uff0c\u6267\u884c \\(g\\leftarrow c\\times g/||g||\\)\u3002
\u4e3a\u4ec0\u4e48\u4f7f\u7528Dropout \u5982\u679c\u53c2\u6570\u592a\u591a\u800c\u8bad\u7ec3\u6837\u672c\u8fc7\u5c11\uff0c\u5bb9\u6613\u51fa\u73b0\u8fc7\u62df\u5408\u3002\u5177\u4f53\u8868\u73b0\u4e3a\uff1a\u5728dev set\u4e0aloss\u5f88\u5c0f\uff0c\u5728test set\u4e0aloss\u5f88\u5927\u3002 \u8fc7\u53bb\u4f1a\u9009\u62e9\u6a21\u578b\u96c6\u6210\uff0c\u8bad\u7ec3\u591a\u4e2a\u6a21\u578b\u8fdb\u884c\u7ec4\u5408\u3002Dropout\u80fd\u6bd4\u8f83\u6709\u6548\u7f13\u89e3\u8fc7\u62df\u5408\u3002\u7531Hinton\u57282012\u5e74\u63d0\u51fa\uff0c\u5e76\u5e94\u7528\u4e8eAlexNet\u3002 Dropout\u7684\u539f\u7406\u662f\u5728\u524d\u5411\u4f20\u64ad\u7684\u65f6\u5019\uff0c\u8ba9\u67d0\u4e2a\u795e\u7ecf\u5143\u7684\u6fc0\u6d3b\u503c\u4ee5\u4e00\u5b9a\u6982\u7387p\u505c\u6b62\u5de5\u4f5c\uff0c\u53ef\u4ee5\u4f7f\u6a21\u578b\u6cdb\u5316\u80fd\u529b\u66f4\u5f3a\uff0c\u56e0\u4e3a\u4e0d\u4f1a\u592a\u4f9d\u8d56\u67d0\u4e9b\u5c40\u90e8\u7279\u5f81\u3002 \u5de5\u4f5c\u6d41\u7a0b\uff1a 1\uff09\u968f\u673a\uff08\u4e34\u65f6\uff09\u5220\u9664\u4e00\u534a\u7684\u9690\u85cf\u795e\u7ecf\u5143\uff0c\u4fdd\u7559\u8f93\u5165\u8f93\u51fa\u795e\u7ecf\u5143\u4e0d\u53d8\uff0c\u88ab\u5220\u9664\u7684\u4fdd\u7559\u53c2\u6570\u4e0d\u53d8\u3002 2\uff09\u5c06\u8f93\u5165\u524d\u5411\u4f20\u64ad\u540e\u540e\u5411\u4f20\u64ad\uff0c\u53ea\u66f4\u65b0\u5269\u4e0b\u795e\u7ecf\u5143\u4e0a\u7684\u53c2\u6570\u3002 3\uff09\u6062\u590d\u88ab\u5220\u6389\u7684\u795e\u7ecf\u5143\uff08\u6b64\u65f6\u88ab\u5220\u9664\u7684\u795e\u7ecf\u5143\u4fdd\u6301\u539f\u6837\uff0c\u800c\u6ca1\u6709\u88ab\u5220\u9664\u7684\u795e\u7ecf\u5143\u5df2\u7ecf\u66f4\u65b0\uff09\u3002 4\uff09\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\u3002
\u4e0b\u9762\u7684\u4e00\u7bc7\u4e00\u7bc7\u6574\u7406 - Microstrong\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2dDropout\u539f\u7406\u89e3\u6790 - \u795e\u7ecf\u7f51\u7edcDropout\u5c42\u4e2d\u4e3a\u4ec0\u4e48dropout\u540e\u8fd8\u9700\u8981\u8fdb\u884crescale\uff1f - bingo\u9171\uff1aL1\u6b63\u5219\u5316\u4e0eL2\u6b63\u5219\u5316 - \u97e6\u4f1f\uff1a\u4ece\u53cd\u5411\u4f20\u64ad\u63a8\u5bfc\u5230\u68af\u5ea6\u6d88\u5931and\u7206\u70b8\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848\uff08\u4eceDNN\u5230RNN\uff0c\u5185\u9644\u8be6\u7ec6\u53cd\u5411\u4f20\u64ad\u516c\u5f0f\u63a8\u5bfc\uff09 - Will\uff1a\u795e\u7ecf\u7f51\u7edc\u8bad\u7ec3\u4e2d\u7684\u68af\u5ea6\u6d88\u5931\u4e0e\u68af\u5ea6\u7206\u70b8 - LSTM\u5982\u4f55\u6765\u907f\u514d\u68af\u5ea6\u5f25\u6563\u548c\u68af\u5ea6\u7206\u70b8\uff1f - LSTM\u5982\u4f55\u6765\u907f\u514d\u68af\u5ea6\u5f25\u6563\u548c\u68af\u5ea6\u7206\u70b8\uff1f
"},{"location":"DL/NLPTech/ml_cheatsheet/#_1","title":"\u56db\u3001\u673a\u5668\u5b66\u4e60","text":"\u9700\u8981\u5728\u56db\u672c\u683c\u5f0f\u4e0d\u4e00\u6837\u7684\u8bcd\u5178\u4e2d\u63d0\u53d6\u51fa\u76f8\u540c\u683c\u5f0f\u7684\u8bcd\u6e90\u4fe1\u606f\uff0c\u8bcd\u6e90\u4e00\u5171\u67099\u5927\u7c7b+\u4e00\u79cd\"Other\"\uff0c\u6587\u672c\u4e2d\u6709\u6570\u4e2a\u8bcd\u6e90\u4fe1\u606f\uff0c\u9700\u8981\u627e\u5230\u6700\u521d\u7684\u90a3\u4e2a\u8bcd\u6e90\u4fe1\u606f\uff0c\u5f52\u52309\u5927\u7c7b\u4e2d\u5e76\u8bb0\u5f55\u4e0b\u6765\u5177\u4f53\u662f\u54ea\u4e00\u7c7b\u3002 \u9700\u8981\u7684\u683c\u5f0f
[{\n\"word\": \"\",\n\"etymology\": [\n{\n\"origin\": \"\",\n\"source\": \"\",\n\"excerpt\": \"\"\n},\n{\n\"origin\": \"\",\n\"source\": \"\",\n\"excerpt\": \"\"\n}\n]\n}]\n
"},{"location":"DL/NLPTech/rule_text/#_2","title":"\u65b9\u6cd5","text":"\"An ultimate origin of a word is the language where a word comes from at the very beginning, or the language where it appears at the earliest time. For the given word %s, please find its ultimate origin of this word from the following passage: %s. You should only answer one word from Anglo, Arabic, Asian, Celtic, English, French, Germanic, Greek, Latin, Spanish, or Other, without outputing anything else. If the origin not provided, just output Other. Origin: %s\" % (\"a\", \"prefix meaning \\\"not,\\\" from Latin. a-, short for ab \\\"away from\\\" (cf. avert), or its cognate, Greek. a-, short for apo \\\"away from, from,\\\" both cognate with Skt. apa \\\"away from,\\\" Goth. af, Old.English. of. \", \"Latin\")\n
\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\uff0c\u4e3a\u4e86\u9632\u6b62ChatGPT\u5c06English\u7406\u89e3\u6210Other\u800c\u975eAnglo\uff0c\u7279\u610f\u5c06English\u6dfb\u52a0\u5728\u4e86\u5907\u9009\u9879\u4e2d\uff0c\u4e4b\u540e\u518d\u5bf9\u8fd4\u56de\u7684English\u7c7b\u522b\u505a\u4e00\u4e2a\u89c4\u5219\u5904\u7406\u3002\u9700\u8981\u5c06\u4e00\u4e2a\u6587\u672c\u5e93\u4e2d\u7684\u6587\u672c\u5206\u8bcd\u540e\u8bcd\u5f62\u8fd8\u539f 1. nltk \u4f18\u70b9\uff1a\u8c03\u7528\u7b80\u5355\uff0c\u5feb \u7f3a\u70b9\uff1a\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a\uff0c\u5f80\u5f80\u9700\u8981\u624b\u52a8\u4e0b\u8f7d\u540e\u653e\u5728\u672c\u5730\u7684nltk\u6587\u4ef6\u5939\u4e2d\uff0c\u51c6\u786e\u7387\u4f4e\u4e00\u4e9b 2. spaCy \u4f18\u70b9\uff1a\u51c6\u786e\u7387\u66f4\u9ad8 \u7f3a\u70b9\uff1a\u8c03\u7528\u6162\uff0c\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a 3. stanza \u4f18\u70b9\uff1a\u51c6\u786e\u7387\u66f4\u9ad8 \u7f3a\u70b9\uff1a\u9884\u8bad\u7ec3\u6a21\u578b\u4e0b\u8f7d\u4e0d\u7a33\u5b9a
\u4e09\u4e2a\u5305\u7684\u63a8\u8350\u7a0b\u5ea6\u6392\u5e8f stanza = spaCy > nltk
"},{"location":"DL/NLPTech/transformer_code/","title":"Notes on Transformer Code","text":""},{"location":"DL/NLPTech/transformer_code/#introduction","title":"Introduction","text":"This note only focuses on the classes and eliminates all other packages or data processing lines.
To implement a Transformer model, the following classes need to be implemented. - embeddings: positional encoding, token embedding, transformer embedding - layers: layer norm, multi-head attention, position-wise feed forward, scale dot product attention - blocks: encoder-layer, decoder-layer - model: encoder, decoder, Transformer
"},{"location":"DL/NLPTech/transformer_code/#utils","title":"Utils","text":"import torch\nfrom torch import nn\n
"},{"location":"DL/NLPTech/transformer_code/#positional-embedding","title":"Positional embedding","text":"class PositionalEncoding(nn.Module):\n\"\"\"\n compute sinusoid encoding.\n \"\"\"\ndef __init__(self, d_model, max_len, device):\n\"\"\"\n constructor of sinusoid encoding class\n :param d_model: dimension of model\n :param max_len: max sequence length\n :param device: hardware device setting\n \"\"\"\nsuper(PositionalEncoding, self).__init__()\n# same size with input matrix (for adding with input matrix)\nself.encoding = torch.zeros(max_len, d_model, device=device)\nself.encoding.requires_grad = False # we don't need to compute gradient\npos = torch.arange(0, max_len, device=device)\npos = pos.float().unsqueeze(dim=1)\n# 1D => 2D unsqueeze to represent word's position\n_2i = torch.arange(0, d_model, step=2, device=device).float()\n# 'i' means index of d_model (e.g. embedding size = 50, 'i' = [0,50])\n# \"step=2\" means 'i' multiplied with two (same with 2 * i)\nself.encoding[:, 0::2] = torch.sin(pos / (10000 ** (_2i / d_model)))\nself.encoding[:, 1::2] = torch.cos(pos / (10000 ** (_2i / d_model)))\n# compute positional encoding to consider positional information of words\ndef forward(self, x):\n# self.encoding\n# [max_len = 512, d_model = 512]\nbatch_size, seq_len = x.size()\n# [batch_size = 128, seq_len = 30]\nreturn self.encoding[:seq_len, :]\n# [seq_len = 30, d_model = 512]\n# it will add with tok_emb : [128, 30, 512]\n
"},{"location":"DL/NLPTech/transformer_code/#token-embedding","title":"Token Embedding","text":"class TokenEmbedding(nn.Embedding):\n\"\"\"\n Token Embedding using torch.nn\n they will dense representation of word using weighted matrix\n \"\"\"\ndef __init__(self, vocab_size, d_model):\n\"\"\"\n class for token embedding that included positional information\n :param vocab_size: size of vocabulary\n :param d_model: dimensions of model\n \"\"\"\nsuper(TokenEmbedding, self).__init__(vocab_size, d_model, padding_idx=1)\n
"},{"location":"DL/NLPTech/transformer_code/#transformer-embedding","title":"Transformer Embedding","text":"Transformer adopts an embedding which is a summation of the token embedding and the positional embedding.
class TransformerEmbedding(nn.Module):\n\"\"\"\n token embedding + positional encoding (sinusoid)\n positional encoding can give positional information to network\n \"\"\"\ndef __init__(self, vocab_size, d_model, max_len, drop_prob, device):\n\"\"\"\n class for word embedding that included positional information\n :param vocab_size: size of vocabulary\n :param d_model: dimensions of model\n \"\"\"\nsuper(TransformerEmbedding, self).__init__()\nself.tok_emb = TokenEmbedding(vocab_size, d_model)\nself.pos_emb = PositionalEncoding(d_model, max_len, device)\nself.drop_out = nn.Dropout(p=drop_prob)\ndef forward(self, x):\ntok_emb = self.tok_emb(x)\npos_emb = self.pos_emb(x)\nreturn self.drop_out(tok_emb + pos_emb)\n
"},{"location":"DL/NLPTech/transformer_code/#scale-dot-product-attention","title":"Scale dot product attention","text":"class ScaleDotProductAttention(nn.Module):\n\"\"\"\n compute scale dot product attention\n Query : given sentence that we focused on (decoder)\n Key : every sentence to check relationship with Qeury(encoder)\n Value : every sentence same with Key (encoder)\n \"\"\"\ndef __init__(self):\nsuper(ScaleDotProductAttention, self).__init__()\nself.softmax = nn.Softmax(dim=-1)\ndef forward(self, q, k, v, mask=None, e=1e-12):\n# input is 4 dimension tensor\n# [batch_size, head, length, d_tensor]\nbatch_size, head, length, d_tensor = k.size()\n# 1. dot product Query with Key^T to compute similarity\nk_t = k.transpose(2, 3) # transpose\nscore = (q @ k_t) / math.sqrt(d_tensor) # scaled dot product\n# 2. apply masking (opt)\nif mask is not None:\nscore = score.masked_fill(mask == 0, -10000)\n# 3. pass them softmax to make [0, 1] range\nscore = self.softmax(score)\n# 4. multiply with Value\nv = score @ v\nreturn v, score\n
"},{"location":"DL/NLPTech/transformer_code/#multi-head-attention","title":"Multi-head Attention","text":"A multi-head attention is a self-attention running in parallel. The multi-head attention module output an attention output and an attention weight matrix with the scaled-dot product module.
class MultiHeadAttention(nn.Module):\n\"\"\"\n q, k, v: with dimension of d_model to d_model. Each is a weight matrix.\n \"\"\"\ndef __init__(self, d_model, n_head):\nsuper(MultiHeadAttention, self).__init__()\nself.n_head = n_head\nself.attention = ScaleDotProductAttention()\nself.w_q = nn.Linear(d_model, d_model)\nself.w_k = nn.Linear(d_model, d_model)\nself.w_v = nn.Linear(d_model, d_model)\nself.w_concat = nn.Linear(d_model, d_model)\ndef forward(self, q, k, v, mask=None):\n\"\"\"\n query = [batch size, query len, hid dim]\n key = [batch size, key len, hid dim]\n value = [batch size, value len, hid dim]\n \"\"\"\n# 1. dot product with weight matrices\nq, k, v = self.w_q(q), self.w_k(k), self.w_v(v)\n# 2. split tensor by number of heads\nq, k, v = self.split(q), self.split(k), self.split(v)\n# 3. do scale dot product to compute similarity\nout, attention = self.attention(q, k, v, mask=mask)\n# 4. concat and pass to linear layer\nout = self.concat(out)\nout = self.w_concat(out)\nreturn out\ndef split(self, tensor):\n\"\"\"\n split tensor by number of head\n :param tensor: [batch_size, length, d_model]\n :return: [batch_size, head, length, d_tensor]\n \"\"\"\nbatch_size, length, d_model = tensor.size()\n# head dimension = hidden dimension // number of heads\nd_tensor = d_model // self.n_head\ntensor = tensor.view(batch_size, length, self.n_head, d_tensor).transpose(1, 2)\n# it is similar with group convolution (split by number of heads)\nreturn tensor\ndef concat(self, tensor):\n\"\"\"\n inverse function of self.split(tensor : torch.Tensor)\n :param tensor: [batch_size, head, length, d_tensor]\n :return: [batch_size, length, d_model]\n \"\"\"\nbatch_size, head, length, d_tensor = tensor.size()\nd_model = head * d_tensor\ntensor = tensor.transpose(1, 2).contiguous().view(batch_size, length, d_model)\nreturn tensor\n
"},{"location":"DL/NLPTech/transformer_code/#position-wise-feed-forward-layer","title":"Position-wise Feed Forward Layer","text":"Another main block inside the encoder is the positionwise ffd. The input is transformed from hid_dim to pf_dim, where pf_dim is usually much larger than the hid_dim. The original transformer has a hid_dim of 512 while a pf_dim of 2048. The purpose of this block is not explained in the Transformer paper.
class PositionwiseFeedForward(nn.Module):\ndef __init__(self, d_model, hidden, drop_prob=0.1):\nsuper(PositionwiseFeedForward, self).__init__()\nself.linear1 = nn.Linear(d_model, hidden)\nself.linear2 = nn.Linear(hidden, d_model)\nself.relu = nn.ReLU()\nself.dropout = nn.Dropout(p=drop_prob)\ndef forward(self, x):\nx = self.linear1(x)\nx = self.relu(x)\nx = self.dropout(x)\nx = self.linear2(x)\nreturn x\n
"},{"location":"DL/NLPTech/transformer_code/#layer-norm","title":"Layer Norm","text":"class LayerNorm(nn.Module):\ndef __init__(self, d_model, eps=1e-12):\nsuper(LayerNorm, self).__init__()\nself.gamma = nn.Parameter(torch.ones(d_model))\nself.beta = nn.Parameter(torch.zeros(d_model))\nself.eps = eps\ndef forward(self, x):\nmean = x.mean(-1, keepdim=True)\nvar = x.var(-1, unbiased=False, keepdim=True)\n# '-1' means last dimension. \nout = (x - mean) / torch.sqrt(var + self.eps)\nout = self.gamma * out + self.beta\nreturn out\n
"},{"location":"DL/NLPTech/transformer_code/#encoder","title":"Encoder","text":"First we build an encoder layer.
class EncoderLayer(nn.Module):\ndef __init__(self, d_model, ffn_hidden, n_head, drop_prob):\nsuper(EncoderLayer, self).__init__()\nself.attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm1 = LayerNorm(d_model=d_model)\nself.dropout1 = nn.Dropout(p=drop_prob)\nself.ffn = PositionwiseFeedForward(d_model=d_model, hidden=ffn_hidden, drop_prob=drop_prob)\nself.norm2 = LayerNorm(d_model=d_model)\nself.dropout2 = nn.Dropout(p=drop_prob)\ndef forward(self, x, src_mask):\n# 1. compute self attention\n_x = x\nx = self.attention(q=x, k=x, v=x, mask=src_mask)\n# 2. add and norm\nx = self.dropout1(x)\nx = self.norm1(x + _x)\n# 3. positionwise feed forward network\n_x = x\nx = self.ffn(x)\n# 4. add and norm\nx = self.dropout2(x)\nx = self.norm2(x + _x)\nreturn x\n
And then the whole encoder. class Encoder(nn.Module):\n\"\"\"\n enc_voc_size: dictionary size\n max_len: max input length\n n_layers: defines #encoder_layers to stack in the encoder\n \"\"\"\ndef __init__(self, enc_voc_size, max_len, d_model, ffn_hidden, n_head, n_layers, drop_prob, device):\nsuper().__init__()\nself.emb = TransformerEmbedding(d_model = d_model, max_len = max_len, \nvoacb_size = enc_voc_size, drop_prob = drop_prob, device = device)\n# a stacked encoder\nself.layers = nn.ModuleList([EncoderLayer(d_model = d_model, ffn_hidden = ffn_hidden, \nn_head = n_head, drop_prob = drop_prob)\nfor _ in range(n_layers)])\ndef forward(self, x, src_mask): # src_mask: during Transformer's training, a forward mask\nx = self.emb(x)\nfor layer in self.layers:\nx = layer(x, src_mask)\nreturn x\n
"},{"location":"DL/NLPTech/transformer_code/#decoder","title":"Decoder","text":"First we build a decoder layer.
class DecoderLayer(nn.Module):\ndef __init__(self, d_model, ffn_hidden, n_head, drop_prob):\nsuper(DecoderLayer, self).__init__()\nself.self_attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm1 = LayerNorm(d_model=d_model)\nself.dropout1 = nn.Dropout(p=drop_prob)\nself.enc_dec_attention = MultiHeadAttention(d_model=d_model, n_head=n_head)\nself.norm2 = LayerNorm(d_model=d_model)\nself.dropout2 = nn.Dropout(p=drop_prob)\nself.ffn = PositionwiseFeedForward(d_model=d_model, hidden=ffn_hidden, drop_prob=drop_prob)\nself.norm3 = LayerNorm(d_model=d_model)\nself.dropout3 = nn.Dropout(p=drop_prob)\ndef forward(self, dec, enc, trg_mask, src_mask):\n# 1. compute self attention\n_x = dec # ideal target\nx = self.self_attention(q=dec, k=dec, v=dec, mask=trg_mask) # predicted target\n# 2. add and norm\nx = self.dropout1(x)\nx = self.norm1(x + _x)\nif enc is not None:\n# 3. compute encoder - decoder attention\n_x = x\nx = self.enc_dec_attention(q=x, k=enc, v=enc, mask=src_mask)\n# 4. add and norm\nx = self.dropout2(x)\nx = self.norm2(x + _x)\n# 5. positionwise feed forward network\n_x = x\nx = self.ffn(x)\n# 6. add and norm\nx = self.dropout3(x)\nx = self.norm3(x + _x)\nreturn x\n
And then the whole decoder. class Decoder(nn.Module):\ndef __init__(self, dec_voc_size, max_len, d_model, ffn_hidden, n_head, n_layers, drop_prob, device):\nsuper().__init__()\nself.emb = TransformerEmbedding(d_model = d_model, drop_prob = drop_prob, \nmax_len = max_len, vocab_size = dec_voc_size, device = devoce)\n# a stacked decoder layer\nself.layers = nn.ModuleList([DecoderLayer(d_model = d_model, ffn_hidden = ffn_hidden, \nn_head = n_head, drop_prob = drop_prob)\nfor _ in range(n_layers)])\nself.linear = nn.Linear(d_model, dec_voc_size)\n\"\"\"\n trg = [batch size, trg len]\n enc_src = [batchsize, src len, hid dim]\n trg_mask = [batch size, 1, trg len, trg len]\n src_mask = [batch size, 1, 1, src len] \n \"\"\"\ndef forward(self, trg, enc_src, trg_mask, src_mask):\ntrg = self.emb(trg)\nfor layer in self.layers:\ntrg = layer(trg, enc_src, trg_mask, src_mask)\n# pass to LM head\noutput = self.linear(trg)\nreturn output\n
"},{"location":"DL/NLPTech/transformer_code/#transformer-model","title":"Transformer Model","text":"The model use forward's src and trg to receive the input and output during both training and testing procedures. During training, the trgs are as references of calculating training loss, while during testing, the testing loss. In the DecoderLayer class, the ideal target and predicted target are compared.
class Transformer(nn.Module):\n\"\"\"\n src_pad_idx: A matrix indicating <pad> positions in the input. <pad>s are not paid attention\n trg_pad_idx: A matrix indicating <pad> positions in the output. <pad>s are not paid attention\n trg_sos_idx: A matrix indicating <sos> positions in the output. Sentence initial.\n enc_voc_size: input encoding size\n dec_voc_size: output encoding size\n d_model: Usually an emphirical value of \\sqrt[4]{#classes}. Originally 512\n n_head: number of heads. Originally 8.\n max_len: limit on the input length\n ffn_hidden: number of hidden layers in the ffn\n n_layers: #layers in stacked encoder and decoder. Originally 6.\n drop_prob: drop out probability\n device: cpu or gpu\n \"\"\"\ndef __init__(self, src_pad_idx, trg_pad_idx, trg_sos_idx, enc_voc_size, dec_voc_size, d_model, n_head, max_len, ffn_hidden, n_layers, drop_prob, device):\nsuper().__init__()\nself.src_pad_idx = src_pad_idx\nself.trg_pad_idx = trg_pad_idx\nself.trg_sos_idx = trg_sos_idx\nself.device = device\nself.encoder = Encoder(d_model=d_model,\nn_head=n_head,\nmax_len=max_len,\nffn_hidden=ffn_hidden,\nenc_voc_size=enc_voc_size,\ndrop_prob=drop_prob,\nn_layers=n_layers,\ndevice=device)\nself.decoder = Decoder(d_model=d_model,\nn_head=n_head,\nmax_len=max_len,\nffn_hidden=ffn_hidden,\ndec_voc_size=dec_voc_size,\ndrop_prob=drop_prob,\nn_layers=n_layers,\ndevice=device)\ndef forward(self, src, trg):\nsrc_mask = self.make_src_mask(src)\ntrg_mask = self.make_trg_mask(trg)\nenc_src = self.encoder(src, src_mask)\noutput = self.decoder(trg, enc_src, trg_mask, src_mask)\nreturn output\ndef make_src_mask(self, src):\nsrc_mask = (src != self.src_pad_idx).unsqueeze(1).unsqueeze(2)\nreturn src_mask\ndef make_trg_mask(self, trg):\ntrg_pad_mask = (trg != self.trg_pad_idx).unsqueeze(1).unsqueeze(3)\ntrg_len = trg.shape[1]\ntrg_sub_mask = torch.tril(torch.ones(trg_len, trg_len)).type(torch.ByteTensor).to(self.device)\ntrg_mask = trg_pad_mask & trg_sub_mask\nreturn trg_mask\n
Let's finally see the default configs.
# GPU device setting\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n# model parameter setting\nbatch_size = 128\nmax_len = 256\nd_model = 512\nn_layers = 6\nn_heads = 8\nffn_hidden = 2048\ndrop_prob = 0.1\n# optimizer parameter setting\ninit_lr = 1e-5\nfactor = 0.9\nadam_eps = 5e-9\npatience = 10\nwarmup = 100\nepoch = 1000\nclip = 1.0\nweight_decay = 5e-4\ninf = float('inf')\n
"},{"location":"DL/NLPTech/transformer_code/#references","title":"References","text":"Vaswani et al. Attention is all you need. 2017 hyunwoongko/transformer: PyTorch Implementation of \"Attention Is All You Need\" (github.com) 6 - Attention is All You Need.ipynb - Colaboratory (google.com)
"},{"location":"DL/NLPTheory/","title":"\u7d22\u5f15","text":"\u8fd9\u4e2a\u7d22\u5f15\u6ca1\u5199\u5b8c
\u800c\u4e14\u6211\u4e5f\u4e0d\u8bb0\u5f97\u4e3a\u4ec0\u4e48\u4e0b\u9762\u653e\u4e86\u8fd9\u5f20\u56fe\u4e86
"},{"location":"DL/NLPTheory/autoregressive/","title":"Autogressive Decoder","text":"TODO
This note collects papers that demonstrates the shortcomings of autoregressive decoders. Two main common concerns about the autoregressive decoders are that they are lacking the generalizability and the efficiency with respect to the amount of training data, due to the limitation of its structure.
"},{"location":"DL/NLPTheory/autoregressive/#limitation-in-generalizability","title":"Limitation in generalizability","text":"Information theory based: compositionality climbing towards NLU: only learning the surface structure of language
In this paper, we
"},{"location":"DL/NLPTheory/autoregressive/#towards-revealing-the-mystery-behind-chain-of-thought-a-theoretical-perspective-2023","title":"Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective (2023)","text":"This paper points out the reason why the CoT success in prompting LLMs. \u589e\u52a0\u6a21\u578b\u7684\u6709\u6548\u6df1\u5ea6
"},{"location":"DL/NLPTheory/autoregressive/#deep-encoder-shallow-decoder-reevaluating-the-speed-quality-tradeoff-in-machine-translation","title":"Deep Encoder, Shallow Decoder: Reevaluating the Speed-Quality Tradeoff in Machine Translation","text":"In section Deep Encoder, Shallow Decoder, this paper discusses the
(Edunov et al., 2018; Pinnis et al., 2018; Ng et al., 2019).
"},{"location":"DL/NLPTheory/autoregressive/#limitation-in-error-accumulation","title":"Limitation in error accumulation","text":"GSM8k uses a verifier to correct the mistakes in reasoning paths, which is a worthy attempt. However, more efficient verification and correction in the early reasoning stage should also be explored. GSM8k and scaling relationship also indicates the log linear-hood has not been reached by the autoregressive decoders.
"},{"location":"DL/NLPTheory/cot/","title":"Chain of Thought Prompting","text":""},{"location":"DL/NLPTheory/cot/#_1","title":"\u4efb\u52a1\u76ee\u6807","text":"\u672c\u5b9e\u9a8c\u65e8\u5728\u6d4b\u8bc4ChatGPT\u5728\u9605\u8bfb\u7406\u89e3\u4efb\u52a1\uff08Multiple-choice Comprehension, MRC\uff09\u4e0a\u7684\u8868\u73b0\uff0c\u5e76\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6316\u6398\u63d0\u793a\u8bcd\uff0c\u901a\u8fc7\u4e0d\u6539\u53d8\u6570\u636e\u96c6\u548c\u6a21\u578b\u53ea\u6539\u53d8\u63d0\u793a\u8bcd\u7684\u65b9\u6cd5\uff0c\u63d0\u9ad8\u5927\u6a21\u578b\u5728MRC\u4e0a\u7684\u8868\u73b0\u3002
"},{"location":"DL/NLPTheory/cot/#_2","title":"\u5b9e\u9a8c\u8bbe\u8ba1","text":"\u4e3a\u8282\u7ea6\u65f6\u95f4\u548c\u91d1\u94b1\u6210\u672c\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5b9e\u9a8c\uff0c\u6211\u4eec\u4ec5\u6d4b\u8bd520\u4e2a\u95ee\u9898
"},{"location":"DL/NLPTheory/cot/#_3","title":"\u6570\u636e\u96c6","text":"AQuA\u6570\u636e\u96c6\u9898\u63d0\u4f9b\u4e86100,000\u9053\u7528\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u7684\u6570\u5b66\u9898\u3002 https://github.com/deepmind/AQuA
"},{"location":"DL/NLPTheory/cot/#benchmark-zero-shot-prompting","title":"Benchmark: Zero-shot Prompting","text":"\u6700\u7b80\u5355\u7684MRC\u95ee\u9898\uff0c\u53ea\u8f93\u5165question\u548coptions The dataset consists of about 100,000 algebraic word problems with natural language rationales. Each problem is a json object consisting of four parts:
question
\u00a0- A natural language definition of the problem to solveoptions
\u00a0- 5 possible options (A, B, C, D and E), among which one is correctrationale
\u00a0- A natural language description of the solution to the problemcorrect
\u00a0- The correct option{\n\"question\": \"A grocery sells a bag of ice for $1.25, and makes 20% profit. If it sells 500 bags of ice, how much total profit does it make?\",\n\"options\": [\"A)125\", \"B)150\", \"C)225\", \"D)250\", \"E)275\"],\n\"rationale\": \"Profit per bag = 1.25 * 0.20 = 0.25\\nTotal profit = 500 * 0.25 = 125\\nAnswer is A.\",\n\"correct\": \"A\"\n}\n
"},{"location":"DL/NLPTheory/cot/#self-consistency","title":"Self-Consistency","text":"# \u5c06\u95ee\u9898\u6309\u53e5\u5b50\u5206\u5f00\uff0c\u5e76\u968f\u673a\u6253\u4e71\u53e5\u5b50\nquestion_sentences = question.split('. ')\nquestion = '. '.join(shuffled(question_sentences))\n# \u5206\u522b\u5c06\u95ee\u9898\u8f93\u5165\u7ed9\u591a\u4e2aChatGPT\nfor i in range(GPT_number):\n answers.append(query(ChatGPT_i, question))\n# \u5c06\u56de\u7b54\u66f4\u591a\u7684\u7b54\u6848vote\u4e3a\u6b63\u786e\u7b54\u6848\nfinal_answer = top_one(answers)\n
\u5bf9\u4e8e\u6bcf\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u5148\u5c06question\u968f\u673a\u6253\u4e71\uff0c\u7136\u540e\u8f93\u5165\u7ed9\u4e09\u4e2agpt\uff08\u4e0d\u76f8\u90bb\u7684\u4e09\u8f6e\uff09\uff0c\u8ba9\u5b83\u4eecvote
"},{"location":"DL/NLPTheory/cot/#multi-step-verifier","title":"multi-step verifier","text":"\u8fd9\u4e2a\u8981\u63a5\u4e00\u4e2averifier model
# \u5206\u522b\u5c06\u95ee\u9898\u8f93\u5165\u7ed9\u591a\u4e2aChatGPT\uff0c\u63a2\u7d22\u5c3d\u53ef\u80fd\u591a\u7684\u63a8\u7406\u8def\u5f84\nfor i in range(GPT_number):\n answers.append(query(ChatGPT_i, question))\n\n# \u4f7f\u7528\u4e00\u4e2afine-tuned\u7684Verifier\uff0c\u6839\u636e\u6570\u636e\u96c6\u6807\u7b7e\u4e3aanswer\u7684\u6bcf\u4e00\u6b65\u6253\u5206\nscores = []\nfor answer in answers:\n score = 0\n for step in answer:\n score += Verifier(step, gold_label)\n scores.append(score)\n\n# \u5c06score\u66f4\u9ad8\u7684\u7b54\u6848vote\u4e3a\u6b63\u786e\u7b54\u6848\nfinal_answer = top_one(scores->answer)\n
\u8fd9\u7bc7\u7684\u6570\u636e\u96c6HotpotQA\uff0c\u8be5\u6570\u636e\u96c6\u5185\u90e8\u63d0\u4f9b\u95ee\u9898\u3001\u56de\u7b54\uff0c\u548c\u76f8\u5e94\u7684\u6587\u7ae0context\u3002
"},{"location":"DL/NLPTheory/cot/#chain-of-thought-prompting-elicits-reasoning-in-large-language-models","title":"Chain-of-Thought Prompting Elicits Reasoning in Large Language Models","text":"\u6dfb\u52a0lets think step by step + \u5e26cot\u76841-shot
prompt = [I, t, q] -> y\nI: instruction\nt: example\nq: question\ny: answer\n
example:
There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n
applicable to
two assumptions
IRCoT mian components
main components
template original paragraph (incorrect)
The first number is 0, the second number is 1, therefore, the third number is 0+1=1.\nThe fourth number is 1+1=2. The fifth number is 1+2=3. The sixth number is 2+3=5.\n(skip..)\nThe 50th number is 32,432,268,459\n
PoT (correct)
length_of_fibonacci_sequence = 50\nfibonacci_sequence = np.zeros(length_of_)\nfibonacci_sequence[0] = 0\nfibonacci_sequence[1] = 1\nfor i in range(3, length_of_fibonacci_sequence):\nfibonacci_sequnce[i] = fibonacci_sequence[i-1] +\nfibonacci_sequence[i-2]\nans = fibonacci_sequence[-1]\n
"},{"location":"DL/NLPTheory/cot/#cos-chain-of-symbol-prompting","title":"CoS (Chain of Symbol Prompting)","text":"template shared model input
There are a set of bricks. The yellow brick C is on top of the brick E . The yellow brick D is on top of the brick A . The yellow brick E is on top of the brick D . The white brick A is on top of the brick B . For the brick B, the color is white. Now we have to get a specific brick. The bricks must now be grabbed from top to bottom, and if the lower brick is to be grabbed, the upper brick must be removed first. How to get brick D?\n
cot prompting (wrong)
The bricks from bottom to top is B, A, D, E, C 1. Remove brick A from the top of brick B. 2. Remove brick E from the top of brick D. 3. Now brick D is the topmost yellow brick and can be grabbed.\n
cos prompting (correct)
B/A/D/E/C C/E E/D D\n
"},{"location":"DL/NLPTheory/embodied_ai/","title":"Embodied AI","text":"TODO
WooooDyy/LLM-Agent-Paper-List: The paper list of the 86-page paper \"The Rise and Potential of Large Language Model Based Agents: A Survey\" by Zhiheng Xi et al. (github.com)
"},{"location":"DL/NLPTheory/embodied_ai/#1-the-birth-of-an-agent-construction-of-llm-based-agents","title":"1. The Birth of An Agent: Construction of LLM-based Agents","text":""},{"location":"DL/NLPTheory/embodied_ai/#11-brain-primarily-composed-of-an-llm","title":"1.1 Brain: Primarily Composed of An LLM","text":""},{"location":"DL/NLPTheory/embodied_ai/#111-natural-language-interaction","title":"1.1.1 Natural Language Interaction","text":""},{"location":"DL/NLPTheory/embodied_ai/#high-quality-generation","title":"High-quality generation","text":"[2023/05]\u00a0Self-Polish: Enhance Reasoning in Large Language Models via Problem Refinement. Zhiheng Xi (Fudan University) et al. arXiv.\u00a0[paper] [code]
[2023-03]\u00a0Large Language Models are Zero-Shot Reasoners. Takeshi Kojima (The University of Tokyo) et al. arXiv.\u00a0[paper][code]
[2023/03]\u00a0Self-Refine: Iterative Refinement with Self-Feedback. Aman Madaan (Carnegie Mellon University) et al. arXiv.\u00a0[paper] [code]
[2022/05]\u00a0Selection-Inference: Exploiting Large Language Models for Interpretable Logical Reasoning. Antonia Creswell (DeepMind) et al. arXiv.\u00a0[paper]
[2022/03]\u00a0Self-Consistency Improves Chain of Thought Reasoning in Language Models. Xuezhi Wang(Google Research) et al. arXiv.\u00a0[paper] [code]
[2022/01]\u00a0Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. Jason Wei (Google Research,) et al. arXiv.\u00a0[paper]
In web scenarios
In life scenarios
Disordered cooperation
Ordered cooperation
[2023/09]\u00a0Exploring Large Language Models for Communication Games: An Empirical Study on Werewolf. Yuzhuang Xu (Tsinghua University) et al. arXiv.\u00a0[paper]
[2023/08]\u00a0AgentVerse: Facilitating Multi-Agent Collaboration and Exploring Emergent Behaviors in Agents. Weize Chen (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation Framework. Qingyun Wu (Pennsylvania State University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0ChatEval: Towards Better LLM-based Evaluators through Multi-Agent Debate. Chi-Min Chan (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/07]\u00a0Communicative Agents for Software Development. Chen Qian (Tsinghua University) et al. arXiv.\u00a0[paper] [code]
[2023/07]\u00a0RoCo: Dialectic Multi-Robot Collaboration with Large Language Models. Zhao Mandi, Shreeya Jain, Shuran Song (Columbia University) et al. arXiv.\u00a0[paper] [code]
[2023/08]\u00a0ProAgent: Building Proactive Cooperative AI with Large Language Models. Ceyao Zhang (The Chinese University of Hong Kong, Shenzhen) et al. arXiv.\u00a0[paper] [code]
TODO
"},{"location":"DL/NLPTheory/explainable_nlp/#survey","title":"Survey","text":""},{"location":"DL/NLPTheory/explainable_nlp/#a-survey-of-the-state-of-explainable-ai-for-natural-language-processing","title":"A Survey of the State of Explainable AI for Natural Language Processing","text":"This survey thoroughly explains the state of explainable NLP. The Introduction discusses two distinguishing criteria for explanability models (1) whether the explanation is for each prediction individually or the model\u2019s prediction process as a whole, and (2) determining whether generating the explanation requires post-processing or not. In Categorization of Explanations, this paper categorizes the explanation models into local (provides information or justification for the model's prediction on a specific input) vs. global (provides similar justification by revealing how the model's predictive process works, independently of any particular input), and self-explaining (also directly interpretable, generates the explanation at the same time as the prediction, e.g. decision trees, rule-based models, and feature saliency models like attention models) vs. post-hoc (an additional operation is performed after the predictions are made). This section also states that the different categories of models can overlap. In section Aspects of Explanations, this paper introduces three types of explanation techniques: (1) explainability techniques (feature importance, surrogate model, example-driven, provenance-based, declarative induction), (2) operations to enable explainability (first-derivation saliency, layer-wise relevance propagation, and input perturbations, attention, LSTM gating signals, explainability-aware architecture design) and (3) visualization techniques (saliency, raw declarative representations, natural language explanation). The section Evaluation introduces several evaluating metrices.
"},{"location":"DL/NLPTheory/explainable_nlp/#opinion-papers","title":"Opinion Papers","text":""},{"location":"DL/NLPTheory/explainable_nlp/#climbing-towards-nlu-on-meaning-form-and-understanding-in-the-age-of-data-2020","title":"Climbing towards NLU: On Meaning, Form, and Understanding in the Age of Data (2020)","text":"This paper argues that the modern NLP models trained on form has no abilities in understanding natural languages based on both the science and philosophy theories. It is structured as follows. In section Large LMs: Hype and analysis, this paper samples example pieces from news and academic literature that exaggerate the understanding abilities in using words including \"understand\"\"comprehension\"\"recall factual knowledge\", and argues that the current LMs have the ability no other than learning the surface linguistic forms of language rather than understanding them. In section What is meaning?, this paper clarifies the meaning of language as the communicative intent that a parole intends to express, and distinguishes the concept \"meaning\" and \"truth\" as the truth is the meaning that is \"grounded\" to the real world. In section The octopus test, this paper detailedly tells a thought experiment of a super intelligent octopus who can mimic the human response by never receiving the knowledge of the grounded real world of the language meaning, by which this paper argues that it might be that how the language receiver decodes the communicative intends affects the conventional meaning of language. In section More constrained thought experiments, two more thought experiments are provided, training the JAVA and training the English LMs without providing the executing methods the communicative intends, and the paper argues that such tasks are impossible. In section Human language acquisition, this paper supports its idea by providing the example of human children's acquiring knowledge is not only grounded on the world image, but also in the interaction with other people. In section Distributional semantics, this paper argues that in NLP, two methods based on the instincts above are training distributional models on corpora augmented with perceptual data, and looking to interaction data (according to Wittgenstein's \"meaning in use\").
"},{"location":"DL/NLPTheory/explainable_nlp/#information-theory-based-compositional-distributional-semantics-2021","title":"Information Theory-based Compositional Distributional Semantics (2021)","text":"According to the abstract, the contribution of this paper can be concluded as proposing the notion of Information Theory-based Compositional Distributional Semantics (ICDS): (i) We first establish formal properties for embedding, composition, and similarity functions based on Shannon\u2019s Information Theory; (ii) we analyze the existing approaches under this prism, checking whether or not they comply with the established desirable properties; (iii) we propose two parameterizable composition and similarity functions that generalize traditional approaches while fulfilling the formal properties; and finally (iv) we perform an empirical study on several textual similarity datasets that include sentences with a high and low lexical overlap, and on the similarity between words and their description. In section Introduction, the author introduces Frege's concepts of compositionality and contextuality, which respectively refers to that \"the meaning of the whole is a function of the meaning of its parts and the syntactic way in which they are combined\", and that \"the meaning of words and utterances is determined by their context\". This section also introduces the main concern of lacking systematicity by the linguists to the NLP, where systematicity is defined as \"A system is said to exhibit systematicity if, whenever it can process a sentence, it can process systematic variants, where systematic variation is understood in terms of permuting constituents or (more strongly) substituting constituents of the same grammatical category.\" Thus, this section introduces that this paper aims to propose a novel system called Information Theory-based Compositional Distributional Semantics (ICDS). In section Related Work, the author introduces a set of properties in selective proper text representation paradigms which includes \"systematicity\", \"usage context\", \"continuity\", and \"information measurbility\", and introduces a series of previous work under this standard. In section Theoretical Framework, this paper first establishes a geometric interpretation of ICDS, that \"The direction of an embedding represents the pragmatic meaning, and the vector norm of embedding represents how much information the literal utterance provides about its meaning in the pragmatic context\", and then proposes the concept of ICDS as \"there are minimal linguistic units whose semantics are determined by their use and whose amount of information is determined by their specificity. On the other hand, the systematicity of language can be captured by compositional mechanisms while preserving the amount of information of the composite utterance\". Section Formal Definition and Properties formally defines the concepts involved in ICDS, where (\\(\\pi\\),\\(\\delta\\), \\(\\bigodot\\)) stand for \"embedding\", \"semantic similarity\", and \"composition function\" respectively. This section points out the embedding function properties (information measurability and angular isometry), composition function properties (composition neutral element, composition norm monotonicity, and sensitivity to stricture), and similarity function properties (angular distance simialrity monotonicity, orthogonal embedding similarity monotonicity, and equidistant embedding simialrity monotonicity). In section Function Analysis and Generalization, this research evaluates several current embedding vector with the proposed framework, while in section Experiment, the semantic representation abilities of several prevailing LLMs including BERT and GPT are evaluated.
"},{"location":"DL/NLPTheory/explainable_nlp/#contrastive-explanations-for-model-interpretability-2021","title":"Contrastive Explanations for Model Interpretability (2021)","text":"This paper proposes a data augmentation method to generate counterexample on the bases of NLI datasets, and proves that by training on patterns \"why A rather than B\" with contrastive learning methods, the model performs better than the previous NLI baselines.
"},{"location":"DL/NLPTheory/explainable_nlp/#using-counterfactual-contrast-to-improve-compositional-generalization-for-multi-step-quantitative-reasoning-2023","title":"Using counterfactual contrast to improve compositional generalization for multi-step quantitative reasoning (2023)","text":""},{"location":"DL/NLPTheory/ling_ebender/","title":"Linguistics Fundamentals for Natural Lanaguage Processing \u7b14\u8bb0","text":"Emily Bender, 2013
100 Essentials from Morphology and Syntax
(\u534a\u5c0f\u65f6\u91cf\u5b50\u6ce2\u52a8\u901f\u8bfb\u6311\u6218 \u5148\u7528\u4e2d\u6587\u5199\u4e86)
from Contents
Lexical Semantics: Senses
Semantic Roles
Collocations and Other Multiword Expressions (MWEs)
Compositional Semantics \u6210\u5206\u8bed\u4e49
Compositional Semantics beyond Predicate-Argument Structure (TODO)
Beyond Sentences
Reference Resolution \u6307\u4ee3\u6d88\u89e3
Presupposition
Information Status and Information Structure
Implicature and Dialogue
The math word problem (MWP) aims to solve simple primary school math problems (in plain-text format) with deep learning methods. The problems usually consists of numbers no larger than 100 and only 5 operators (+, -, *, / and =). This blog is structured as follows. The Dataset part will introduce two main types, one indicating the locations of variables, and the other simply embedding the math formula within the natural language texts. The Methods parts will introduce several prevailing methods in solving this task, including both the models and workflows that improves the accuracy of models.
"},{"location":"DL/NLPTheory/mwp/#surveys","title":"Surveys","text":""},{"location":"DL/NLPTheory/mwp/#the-gap-of-semantic-parsing-a-survey-on-automatic-math-word-problem-solvers-2019","title":"The Gap of Semantic Parsing: A Survey on Automatic Math Word Problem Solvers (2019)","text":"This survey provides a comprehensive introduction to the MWP datasets and methods prior to 2019. This survey defines three stages of MWP solving, the Rule-based matching stage (1960-2010), Semantic parsing, feature engineering and statistical learning stage (2011-2017), and Deep learning and reinforcement learning stage (2017-2019).
"},{"location":"DL/NLPTheory/mwp/#towards-tractable-mathematical-reasoning-challenges-strategies-and-opportunities-for-solving-math-word-problems-2021","title":"Towards Tractable Mathematical Reasoning: Challenges, Strategies, and Opportunities for Solving Math Word Problems (2021)","text":"This survey introduces the contemporary MWP datasets til 2021, and methods including rule-based, and neural network encoder-decoder structures. Specifically, this paper concludes three strategies for math word solving, (i) direct answer generation, (ii) expression tree generation for inferring answers, and (iii) template retrieval for answer computation. Considering the type of problem solving method, this paper concludes two classes. The first class is non-neural approaches (rule-base or pattern matching approaches, semantic parsing, and statistical machine learning approaches), within which a particular strategy of applying domain knowledge in classifying the problems (e.g. into change, part-whole and compare classes). The second class is neural approaches, including intuitions of (i) predicting the answer directly (ii) generating a set of equations or mathematical expressions and inferring answers from the by executing them (iii) retrieving the templates from a pool of templates derived from training data and augmenting numerical quantities to compute the answer. These neural approaches generally follow encoder-decoder architectures, which fall in four types (i) seq-to-seq (ii) Transformer-to-tree (iii) seq-to-tree (iv) graph-to-tree. Among the four methods, the tree-structured decoder attend both parents and siblings to generate the next token, while the bottom-up representation of sub-tree of a sibling could further help to derive better outcomes. The graph-based encoder aims to learn different types of relationships among the constituents of MWPs. This section also mentions that \"Data augmentation is a popular preprocessing technique to increase the size of training data\" (reverse operation-based augmentation techniques, different traversal orders of expression trees, and weak supervision). In section Math Reasoning in Neural Approaches, this paper mentions several further topics under math reasoning, interpretability and explainability, infusing explicit and definitive knowledge, and reinforcement learning.
"},{"location":"DL/NLPTheory/mwp/#datasets","title":"Datasets","text":""},{"location":"DL/NLPTheory/mwp/#mawps-a-math-word-problem-repository-2016","title":"MAWPS: A Math Word Problem Repository (2016)","text":"sroy9/mawps: Code for MAWPS: A Math Word Problem Repository (github.com) The data format is as follows.
[\n{\n\"iIndex\": 1,\n\"sQuestion\": \"Joan found 70.0 seashells on the beach. She gave Sam some of her seashells . She has 27.0 seashells . How many seashells did she give to Sam ?\",\n\"lEquations\": [\"X=(70.0-27.0)\"],\n\"lSolutions\": [43.0]\n},\n]\n
"},{"location":"DL/NLPTheory/mwp/#math23k-deep-neural-solver-for-math-word-problems-2017","title":"Math23k: Deep Neural Solver for Math Word Problems (2017)","text":"Deep Neural Solver for Math Word Problems (aclanthology.org) This dataset is in Chinese.
Problem: Dan have 2 pens, Jessica have 4 pens. How many pens do they have in total ? \nEquation: x = 4+2 \nSolution: 6\n
"},{"location":"DL/NLPTheory/mwp/#mathqa-2019","title":"MathQA (2019)","text":"MathQA-Dataset (math-qa.github.io) This paper proposes a math dataset which enhances the AQuA dataset by providing fully-specified operational programs. This dataset has a diverse range of operators.
"},{"location":"DL/NLPTheory/mwp/#math-2021","title":"MATH (2021)","text":"arxiv.org/pdf/2103.03874.pdf MATH is a LaTeX format dataset, with its answer highlighted in a square block.
"},{"location":"DL/NLPTheory/mwp/#svmap","title":"SVMAP","text":"arkilpatel/SVAMP: NAACL 2021: Are NLP Models really able to Solve Simple Math Word Problems? (github.com) This dataset does not distinguish the data with the texts. An example data is as follows.
"},{"location":"DL/NLPTheory/mwp/#gsm8k-grade-school-math-2021","title":"GSM8k: grade school math (2021)","text":"Collected by OpenAI, this dataset consists of math problems in natural language descriptions, with the math formulas highlighted with special notes.The numbers are not explicitly highlighted with special symbols. Several examples of the data format are as follows.
"},{"location":"DL/NLPTheory/mwp/#draw","title":"DRAW","text":"Providing 1000 grounded word problems.
"},{"location":"DL/NLPTheory/mwp/#algebra","title":"Algebra","text":""},{"location":"DL/NLPTheory/mwp/#asdiv","title":"AsDiv","text":""},{"location":"DL/NLPTheory/mwp/#multiarith","title":"MultiArith","text":""},{"location":"DL/NLPTheory/mwp/#singleeq","title":"SingleEq","text":""},{"location":"DL/NLPTheory/mwp/#methods","title":"Methods","text":""},{"location":"DL/NLPTheory/mwp/#models","title":"Models","text":"Prior to 2017, the models for solving MWP are mainly concerning with neural networks. After Transformer has been released in 2017, attention-based models have been thriving. The novel models based on Transformer are mainly modifying the encoder and decoder structures, among which there are graph-encoder and tree-decoders.
"},{"location":"DL/NLPTheory/mwp/#graph-to-tree-learning-for-solving-math-word-problems-2020","title":"Graph-to-Tree Learning for Solving Math Word Problems (2020)","text":"This paper proposes a attention-based model Graph2Tree, consisting of graph-based encoder and a tree-based decoder. The math word problems are constructed into Quantity Comparison Graph.
"},{"location":"DL/NLPTheory/mwp/#math-word-problem-solving-with-explicit-numerical-values-2021","title":"Math Word Problem Solving with Explicit Numerical Values (2021)","text":""},{"location":"DL/NLPTheory/mwp/#math23k","title":"Math23K","text":"A novel approach called NumS2T is proposed to solve MWP. NumS2T is constructed with (a) an attention-based seq2seq model to generate its math expressions, (b) a numerical value encoder to obtain the number-aware problem state which are then concatenated with the problem hidden state in (a) to obtain number-aware problem representation, and (c) a numerical properties prediction mechanism for comparing the paired numerical values, determining the category of each numeral and measuring whether they should appear in the target expression.!
"},{"location":"DL/NLPTheory/mwp/#learning-to-reason-deductively-math-word-problem-solving-as-complex-relation-extraction-2022","title":"Learning to Reason Deductively: Math Word Problem Solving as Complex Relation Extraction (2022)","text":"This paper proposes a novel approach
"},{"location":"DL/NLPTheory/mwp/#workflows","title":"Workflows","text":"Most of the recent works follow the method of knowledge distilling, which means to generate high quality data with LLMs and then train a small model with the generated (and sometimes then augmented) data. The workflow of such tasks mainly assembles that of the following paper.
"},{"location":"DL/NLPTheory/mwp/#large-language-models-are-reasoning-teachers","title":"Large Language Models Are Reasoning Teachers","text":"This paper proposes a knowledge distilling method in solving math reasoning problems.
"},{"location":"DL/NLPTheory/mwp/#solving-math-word-problems-via-cooperative-reasoning-induced-language-models-acl-2023","title":"Solving Math Word Problems via Cooperative Reasoning induced Language Models (ACL 2023)","text":"This paper develops a cooperative reasoning-induced PLM for solving MWPs called Cooperative Reasoning (CoRe), with a generator to generate reasoning paths and a verifier to supervise the evaluation.
"},{"location":"DL/NLPTheory/mwp/#scaling-relationship-on-learning-mathematical-reasoning-with-large-language-models-2023","title":"Scaling Relationship on Learning Mathematical Reasoning with Large Language Models (2023)","text":""},{"location":"DL/NLPTheory/mwp/#gsm8k","title":"GSM8k","text":"This paper mainly focus on the following two questions: (i) Which is a better performance indicator of LLMs? (pre-training loss amount/model size) (ii) How to improve small model's performance by data augmentation? To answer the second question, this paper proposes a novel methods in data augmentation in the LLM data generation step which is called Rejection Finetuning (RFT). The algorithm of sampling data in RFT mainly adopts the thought of rejection sampling, which is expressed in the following pseudo-code. This paper assumes such an algorithm will yield as many as possible diverse reasoning paths. The workflow of the RFT method is illustrated as follows, where the SFT stands for supervised finetuning. With the novel method RFT, small models such as Llama-7b yields an accuracy of at most 49.7% on GSM8k, 14% higher than the previous SOTA method SFT.
"},{"location":"DL/NLPTheory/mwp/#pal","title":"PAL","text":"This work is a prompt engineering work.
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? \nA: Roger started with 5 tennis balls. tennis_balls = 5 2 cans of 3 tennis balls each is bought_balls = 2 * 3 tennis balls. The answer is answer = tennis_balls + bought_balls \nQ: The bakers at the Beverly Hills Bakery baked 200 loaves of bread on Monday morning. They sold 93 loaves in the morning and 39 loaves in the afternoon. A grocery store returned 6 unsold loaves. How many loaves of bread did they have left?\n
A: The bakers started with 200 loaves loaves_baked = 200 They sold 93 in the morning and 39 in the afternoon loaves_sold_morning = 93 loaves_sold_afternoon = 39 The grocery store returned 6 loaves. loaves_returned = 6 The answer is answer = loaves_baked - loaves_sold_morning - loaves_sold_afternoon + loaves_returned\n
"},{"location":"DL/NLPTheory/mwp/#preview","title":"Preview","text":""},{"location":"DL/NLPTheory/neural_symbolic/","title":"Neural Symbolic AI","text":"TODO
Neural-Symbolic Computing: An Effective Methodology for Principled Integration of Machine Learning and Reasoning This paper provides an introduction to neural symbolic computing, indicating that the neural symbolic AI aim at integrating as learning from the environment and the ability to reason from what has been learned.
"},{"location":"DL/NLPTheory/nli/","title":"Natural Language Inference (NLI)","text":"TODO: \u786e\u5b9a\u5199\u4e0d\u51fa\u6765\u5148\u653e\u5f03\u5427
"},{"location":"DL/NLPTheory/nli/#task-description","title":"Task Description","text":"Natural Language Inference (NLI) problem concerns the logic reasoning relationship of sentences or facts in natural language texts.
"},{"location":"DL/NLPTheory/nli/#relevant-survey","title":"Relevant Survey","text":"There are several relevant surveys on the NLI tasks.
"},{"location":"DL/NLPTheory/nli/#a-survey-of-paraphrasing-and-textual-entailment-method-2017","title":"A survey of paraphrasing and textual entailment method (2017)","text":"https://www.jair.org/index.php/jair/article/view/10651
"},{"location":"DL/NLPTheory/nli/#an-overview-of-natural-language-inference-data-collection-the-way-forward-2017","title":"An overview of Natural Language Inference Data Collection: The way forward? (2017)","text":"https://aclanthology.org/W17-7203.pdf
"},{"location":"DL/NLPTheory/nli/#logical-formalizations-of-commonsense-reasoning-a-survey-2017","title":"Logical formalizations of commonsense reasoning: a survey (2017)","text":"https://www.jair.org/index.php/jair/article/view/11076/26258
"},{"location":"DL/NLPTheory/nli/#recent-advances-in-natural-language-inference-a-survey-of-benchmarks-resources-and-approaches-2019","title":"Recent Advances in Natural Language Inference: A Survey of Benchmarks, Resources, and Approaches (2019)","text":"https://arxiv.org/abs/1904.01172
"},{"location":"DL/NLPTheory/nli/#a-survey-on-recognizing-textual-entailment-as-an-nlp-evaluation-2020","title":"A Survey on Recognizing Textual Entailment as an NLP Evaluation (2020)","text":"https://aclanthology.org/2020.eval4nlp-1.10.pdf
"},{"location":"DL/NLPTheory/nli/#symbolic-and-neural-approaches-to-natural-language-inference-2021","title":"SYMBOLIC AND NEURAL APPROACHES TO NATURAL LANGUAGE INFERENCE (2021)","text":"https://scholarworks.iu.edu/dspace/bitstream/handle/2022/26642/dissertation_final_hai_hu.pdf?sequence=1&isAllowed=y
"},{"location":"DL/NLPTheory/nli/#natural-language-inference-a-dissertation-bill-maccartney","title":"Natural Language Inference a dissertation (BIll MacCartney)","text":"https://www-nlp.stanford.edu/~wcmac/papers/nli-diss.pdf
"},{"location":"DL/NLPTheory/nli/#toward-reasoning-in-large-language-models-a-survey","title":"Toward reasoning in large language models: A survey","text":"https://arxiv.org/abs/2212.10403 The structure of this paper is as follows. This paper first provides differentiations among deductive reasoning, inductive reasoning and abductive reasoning, and among formal reasoning and informal reasoning. At the end, this paper states that it focuses explicitly in informal deductive reasoning in large language models. Deductive reasoning
Premise: All mammals have kidneys. \nPremise: All whales are mammals. \nConclusion: All whales have kidneys.\n
Inductive reasoning Observation: Every time we see a creature with wings, it is a bird. \nObservation: We see a creature with wings. \nConclusion: The creature is likely to be a bird.\n
Abductive reasoning Observation: The car cannot start and there is a puddle of liquid under the engine. \nConclusion: The most likely explanation is that the car has a leak in the radiator.\n
In the Towards Reasoning in Large Language Models section, this survey discusses three main methods in solving math reasoning problems. For fully supervised fine-tuning method, it is suggested that the two main limitations are the lack of the datasets containing explicit reasoning, and the lack of the generializability of models. For CoT methods, this paper introduces CoT as a trigger of LLMs reasoning ability, and introduces several variant of CoT including zero-shot CoT, and three methods towards Rationale engineering, Rational refinement (complexity-based prompting, algorithmic prompting, and Auto-CoT), Rationale exploration (self-consistency probing), and Rationale verification. The Hybrid Method section introduces the Reasoning-Enhanced Training and Prompting and the Bootstrapping & Self-Improving methods. In section Measuring Reasoning in Large Language Models, this paper introduces several task variants to the reasoning task, including Arithmetic Reasoning, Commonsense Reasoning and Symbolic Reasoning. Four findings are proposed in this survey, which are that \"Reasoning seems an emergent ability of LLMs\", \"CoT elicits reasoning of LLMs\", \"LLMs show human-like content effect on reasoning\", and \"LLMs are still unskilled at complex reasoning\". This paper also points out concerns on whether LLMs are reasoning or simply \"generating reasoning-like responses\".
"},{"location":"DL/NLPTheory/nli/#dataset","title":"Dataset","text":"The natural language reasoning datasets usually follows the multiple choice structure -- given a premise consisting of a series of sentences and a hypothesis of usually one-sentence length, the label indicates the relationship between them, which are \"entailment\", \"neutral\" or \"contradiction\". According to the length of the premises, the NLI datasets can be classified as sentence-level, paragraph-level and document-level.
"},{"location":"DL/NLPTheory/nli/#sentence-level","title":"Sentence-level","text":""},{"location":"DL/NLPTheory/nli/#paragraph-level","title":"Paragraph-level","text":""},{"location":"DL/NLPTheory/nli/#document-level","title":"Document-level","text":""},{"location":"DL/NLPTheory/nli/#method","title":"Method","text":""},{"location":"DL/NLPTheory/nli/#sentence-level_1","title":"Sentence-level","text":""},{"location":"DL/NLPTheory/nli/#paragraph-level_1","title":"Paragraph-level","text":""},{"location":"DL/NLPTheory/nli/#document-level_1","title":"Document-level","text":""},{"location":"DL/NLPTheory/nli/#preview","title":"Preview","text":""},{"location":"DL/Python/broadcastable_vector/","title":"Broadcastble Vector","text":"Broadcasting is a mechanism which allows tensors with different numbers of dimensions to be added or multiplied together by (virtually) replicating the smaller tensor along the dimensions that it is lacking.
One tensor is broadcastable to another if the following rules hold. - Each tensor has at least one dimension. - When iterating over the dimension size, starting at the trailing dimension, the dimension sizes must either be equal, one of them is 1, or one of them does not exist.
Examples Same shapes are always broadcastable.
x = torch.empty(5,7,3)\ny = torch.empty(5,7,3)\n
If one of the vectors does not have at least one dimension, they are not broadcastable.
x = torch.empty((0,))\ny = torch.empty(2,2)\n
Lining up is from right to left. x and y can line up trailing dimensions
x = torch.empty(5, 3, 4, 1)\ny = torch.empty( 3, 1, 1)\n
1st trailing dimension: x and y both have dim 1 2nd trailing dimension: y has 1 3rd trailing dimension: x = y 4th trailing dimension: y's dimension does not exist"},{"location":"DL/Python/ipdb/","title":"IPDB","text":"Python\u8c03\u8bd5\u5de5\u5177
\u5b89\u88c5
pip install ipdb\n
\u4f7f\u7528
import ipdb\n# some code\nx = 10\nipdb.set_trace()\ny = 20\n# other code\n
\u6216\u8005\u4f7f\u7528\u547d\u4ee4\u884c
python -m ipdb your_code.py\n
"},{"location":"DL/Python/pandas_dataframe/","title":"Pandas Dataframe","text":"\u63d0\u793a\uff1a\u4f46\u662fpandas\u771f\u7684\u96be\u7528\uff0c\u91cc\u9762\u5b9e\u73b0\u633a\u4e71\u7684\uff0c\u7ecf\u5e38\u51fa\u73b0\u672a\u77e5\u7684\u526f\u4f5c\u7528\uff08\u4e5f\u53ef\u80fd\u602a\u6211db\u6ca1\u5b66\u597dorz\uff09\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528csv\u5305
\u53c8\u53c8\uff1apandas\u597d\u50cf\u6700\u8fd1\uff08\u630723\u5e7411\u6708\uff09\u6709\u4e2a\u62df\u4eba\u4e00\u70b9\u7684\u66f4\u65b0\uff0c\u6211\u8e72\u4e00\u8e72
"},{"location":"DL/Python/pandas_dataframe/#_1","title":"\u589e","text":"\u6309\u5217\u589e\u52a0
citys = ['ny','zz','xy']\ndf.insert(0,'city',citys) #\u5728\u7b2c0\u5217\uff0c\u52a0\u4e0acolumn\u540d\u79f0\u4e3acity\uff0c\u503c\u4e3acitys\u7684\u6570\u503c\u3002\njobs = ['student','AI','teacher']\ndf['job'] = jobs #\u9ed8\u8ba4\u5728df\u6700\u540e\u4e00\u5217\u52a0\u4e0acolumn\u540d\u79f0\u4e3ajob\uff0c\u503c\u4e3ajobs\u7684\u6570\u636e\u3002\ndf.loc[:,'salary'] = ['1k','2k','2k','2k','3k'] #\u5728df\u6700\u540e\u4e00\u5217\u52a0\u4e0acolumn\u540d\u79f0\u4e3asalary\uff0c\u503c\u4e3a\u7b49\u53f7\u53f3\u8fb9\u6570\u636e\u3002\n
\u6309\u884c\u589e\u52a0
df.loc[4] = ['zz','mason','m',24,'engineer\u2019] #\u82e5df\u4e2d\u6ca1\u6709index\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\u7684\u8bdd\uff0c\u8be5\u884c\u4ee3\u7801\u4f5c\u7528\u662f\u5f80df\u4e2d\u52a0\u4e00\u884cindex\u4e3a\u201c4\u201d\uff0c\u503c\u4e3a\u7b49\u53f7\u53f3\u8fb9\u503c\u7684\u6570\u636e\u3002\u82e5df\u4e2d\u5df2\u7ecf\u6709index\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\uff0c\u5219\u8be5\u884c\u4ee3\u7801\u4f5c\u7528\u662f\u628adf\u4e2dindex\u4e3a\u201c4\u201d\u7684\u8fd9\u4e00\u884c\u4fee\u6539\u4e3a\u7b49\u53f7\u53f3\u8fb9\u6570\u636e\u3002\ndf_insert = pd.DataFrame({'name':['mason','mario'],'sex':['m','f'],'age':[21,22]},index = [4,5])\nndf = df.append(df_insert,ignore_index = True) #\u8fd4\u56de\u6dfb\u52a0\u540e\u7684\u503c\uff0c\u5e76\u4e0d\u4f1a\u4fee\u6539df\u7684\u503c\u3002ignore_index\u9ed8\u8ba4\u4e3aFalse\uff0c\u610f\u601d\u662f\u4e0d\u5ffd\u7565index\u503c\uff0c\u5373\u751f\u6210\u7684\u65b0\u7684ndf\u7684index\u91c7\u7528df_insert\u4e2d\u7684index\u503c\u3002\u82e5\u4e3aTrue\uff0c\u5219\u65b0\u7684ndf\u7684index\u503c\u4e0d\u4f7f\u7528df_insert\u4e2d\u7684index\u503c\uff0c\u800c\u662f\u81ea\u5df1\u9ed8\u8ba4\u751f\u6210\u3002\n
"},{"location":"DL/Python/pandas_dataframe/#_2","title":"\u5220","text":"\u5220\u9664\u884c
df.drop([1,3],axis = 0,inplace = False)#\u5220\u9664index\u503c\u4e3a1\u548c3\u7684\u4e24\u884c\uff0c\n
\u5220\u9664\u5217
df.drop(['name'],axis = 1,inplace = False) #\u5220\u9664name\u5217\u3002\ndel df['name'] #\u5220\u9664name\u5217\u3002\nndf = df.pop('age\u2019)#\u5220\u9664age\u5217\uff0c\u64cd\u4f5c\u540e\uff0cdf\u90fd\u4e22\u6389\u4e86age\u5217,age\u5217\u8fd4\u56de\u7ed9\u4e86ndf\u3002\n
"},{"location":"DL/Python/pandas_dataframe/#_3","title":"\u6539","text":"\u6539\u884c\u5217\u6807\u9898
df.columns = ['name','gender','age'] #\u5c3d\u7ba1\u6211\u4eec\u53ea\u60f3\u628a\u2019sex\u2019\u6539\u4e3a\u2019gender\u2019\uff0c\u4f46\u662f\u4ecd\u7136\u8981\u628a\u6240\u6709\u7684\u5217\u5168\u5199\u4e0a\uff0c\u5426\u5219\u62a5\u9519\u3002\ndf.rename(columns = {'name':'Name','age':'Age'},inplace = True) #\u53ea\u4fee\u6539name\u548cage\u3002inplace\u82e5\u4e3aTrue\uff0c\u76f4\u63a5\u4fee\u6539df\uff0c\u5426\u5219\uff0c\u4e0d\u4fee\u6539df\uff0c\u53ea\u662f\u8fd4\u56de\u4e00\u4e2a\u4fee\u6539\u540e\u7684\u6570\u636e\u3002\ndf.index = list('abc')#\u628aindex\u6539\u4e3aa,b,c.\u76f4\u63a5\u4fee\u6539\u4e86df\u3002\ndf.rename({1:'a',2:'b',3:'c'},axis = 0,inplace = True)#\u65e0\u8fd4\u56de\u503c\uff0c\u76f4\u63a5\u4fee\u6539df\u7684index\u3002\n
\u6539\u6570\u503c
df.loc[1,'name'] = 'aa' #\u4fee\u6539index\u4e3a\u20181\u2019\uff0ccolumn\u4e3a\u2018name\u2019\u7684\u90a3\u4e00\u4e2a\u503c\u4e3aaa\u3002\ndf.loc[1] = ['bb','ff',11] #\u4fee\u6539index\u4e3a\u20181\u2019\u7684\u90a3\u4e00\u884c\u7684\u6240\u6709\u503c\u3002\ndf.loc[1,['name','age']] = ['bb',11] #\u4fee\u6539index\u4e3a\u20181\u2019\uff0ccolumn\u4e3a\u2018name\u2019\u7684\u90a3\u4e00\u4e2a\u503c\u4e3abb\uff0cage\u5217\u7684\u503c\u4e3a11\u3002\n
\u4f7f\u7528iloc[row_index, column_index]
df.iloc[1,2] = 19#\u4fee\u6539\u67d0\u4e00\u65e0\u7d20\ndf.iloc[:,2] = [11,22,33] #\u4fee\u6539\u4e00\u6574\u5217\ndf.iloc[0,:] = ['lily','F',15] #\u4fee\u6539\u4e00\u6574\u884c\n
"},{"location":"DL/Python/pandas_dataframe/#lociloc","title":"\u7b5b\u9009\u6570\u636e\u65b9\u6cd5loc\u3001iloc","text":"import pandas as pd\nimport numpy as np\ndates = pd.date_range('20200315', periods = 5)\ndf = pd.DataFrame(np.arange(20).reshape(5,4), index = dates, columns = ['A', 'B','C','D'])\nprint(df)\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n2020-03-18 12 13 14 15\n2020-03-19 16 17 18 19\n
print(df['A'])\n
#\u8f93\u51fa\n2020-03-15 0\n2020-03-16 4\n2020-03-17 8\n2020-03-18 12\n2020-03-19 16\nFreq: D, Name: A, dtype: int64\n
print(df.A)\n
#\u8f93\u51fa\n2020-03-15 0\n2020-03-16 4\n2020-03-17 8\n2020-03-18 12\n2020-03-19 16\nFreq: D, Name: A, dtype: int64\n
\u8de8\u8d8a\u591a\u884c\u6216\u8005\u591a\u5217
print(df[0:3])\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n
print(df['20200315' : '20200317'])\n
#\u8f93\u51fa\nA B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n
"},{"location":"DL/Python/pandas_dataframe/#loc","title":"loc\u7eaf\u6807\u7b7e\u7b5b\u9009","text":"import pandas as pd\nimport numpy as np\ndates = pd.date_range('20200315', periods = 5)\ndf = pd.DataFrame(np.arange(20).reshape(5,4), index = dates, columns = ['A', 'B','C','D'])\nprint(df)\nprint('\\n')\nprint(df.loc['20200315']) #\u6253\u5370\u67d0\u4e00\u884c\u7684\u6807\u7b7e\nprint('\\n')\nprint(df.loc[:,['A', 'B']]) #\u6253\u5370A\u3001B\u5c5e\u6027\u7684\u6240\u6709\u884c\nprint('\\n')\nprint(df.loc['20200315', ['A', 'B','C']])\n
#\u8f93\u51fa\n A B C D\n2020-03-15 0 1 2 3\n2020-03-16 4 5 6 7\n2020-03-17 8 9 10 11\n2020-03-18 12 13 14 15\n2020-03-19 16 17 18 19\n\nA 0\nB 1\nC 2\nD 3\nName: 2020-03-15 00:00:00, dtype: int64\n\n A B\n2020-03-15 0 1\n2020-03-16 4 5\n2020-03-17 8 9\n2020-03-18 12 13\n2020-03-19 16 17\n\nA 0\nB 1\nC 2\nName: 2020-03-15 00:00:00, dtype: int64\n
"},{"location":"DL/Python/pandas_dataframe/#_4","title":"\u67e5","text":""},{"location":"DL/Python/pandas_dataframe/#_5","title":"\u904d\u5386","text":"iterrows(): \u6309\u884c\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u884c\u8fed\u4ee3\u4e3a(index, Series)\u5bf9\uff0c\u53ef\u4ee5\u901a\u8fc7row[name]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\u3002 itertuples(): \u6309\u884c\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u884c\u8fed\u4ee3\u4e3a\u5143\u7956\uff0c\u53ef\u4ee5\u901a\u8fc7row[name]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\uff0c\u6bd4iterrows()\u6548\u7387\u9ad8\u3002 iteritems():\u6309\u5217\u904d\u5386\uff0c\u5c06DataFrame\u7684\u6bcf\u4e00\u5217\u8fed\u4ee3\u4e3a(\u5217\u540d, Series)\u5bf9\uff0c\u53ef\u4ee5\u901a\u8fc7row[index]\u5bf9\u5143\u7d20\u8fdb\u884c\u8bbf\u95ee\u3002
"},{"location":"DL/Python/python_object/","title":"Python\u9762\u5411\u5bf9\u8c61\u8bed\u6cd5","text":""},{"location":"DL/Python/python_object/#class","title":"Class","text":"\u5e38\u89c1\u8fd0\u7b97\u7b26\u91cd\u8f7d\u65b9\u6cd5
"},{"location":"DL/Python/python_object/#operator-at","title":"operator at(@)","text":"An @
at the beginning of a line is used for a class and function decorator. Example:
class Pizza(object):\ndef __init__(self):\nself.toppings = []\ndef __call__(self, topping):\n# When using '@instance_of_pizza' before a function definition\n# the function gets passed onto 'topping'.\nself.toppings.append(topping())\ndef __repr__(self):\nreturn str(self.toppings)\npizza = Pizza()\n@pizza\ndef cheese(): # this function passes to topping()\nreturn 'cheese'\n@pizza\ndef sauce():\nreturn 'sauce'\nprint pizza\n# ['cheese', 'sauce']\n
def decorator(func):\nreturn func\n@decorator\ndef some_func():\npass\n
is equivalent to this code def decorator(func):\nreturn func\ndef some_func():\npass\nsome_func = decorator(some_func)\n
"},{"location":"DL/Python/python_object/#kwargs","title":"**kwargs","text":"kwargs is a parameter in Python's functions, which takes an arbitrary numbers of parameters. Usage:
def\u00a0print_keyword_args(**kwargs):\n# kwargs is a dict of the keyword args passed to the function\nfor\u00a0key, value\u00a0in\u00a0kwargs.iteritems():\nprint\u00a0\"%s = %s\"\u00a0% (key, value)\nprint_keyword_args(first_name=\"John\", last_name=\"Doe\")\n
Output: first_name = John last_name = Doe"},{"location":"DL/Python/python_object/#_1","title":"\u6570\u7ec4\u62f7\u8d1d","text":"s1 = [[]] * 3 ## \u662f\u6d45\u62f7\u8d1d\ns1[1].append('xyx') ## [['xyx'], ['xyx'], ['xyx']]\ns2 = [[] for _ in 3] ## \u662f\u6df1\u62f7\u8d1d\ns2[1].append('xyx') ## [[], ['xyx'], []]\n
"},{"location":"DL/Python/pytorch/","title":"Pytorch \u901f\u67e5","text":""},{"location":"DL/Python/pytorch/#nnmodulelist-and-nnsequential","title":"nn.ModuleList and nn.Sequential","text":"TLDR: nn.ModuleList
is a list which is indexable and without extra functions, while nn.Sequential
is a workflow with order and ability to call the forward functions automatically.
Please refer to more details from PyTorch \u4e2d\u7684 ModuleList \u548c Sequential: \u533a\u522b\u548c\u4f7f\u7528\u573a\u666f - \u77e5\u4e4e (zhihu.com).
"},{"location":"DL/Python/pytorch/#forward-function-in-pytorch","title":"Forward function in Pytorch","text":"In training models with Pytorch, there is no need to explicitly call the forward function. The way to call the forward function is as follows.
class Module(nn.Module):\ndef __init__(self):\nsuper().__init__()\n# ...\ndef forward(self, x):\n# ...\nreturn x\ndata = data\nmodel = Module()\nmodel(data)\n
instead of model.forward(data)
. This is because model(data)
equals mode.forward(data)
itself. In class nn.Module
, the function __call__
has been overloaded as def __call__(self, data):\nreturn self.forward(data)\n
"},{"location":"DL/Python/pytorch/#element-wise-matmul-dot","title":"*\u662felement wise @\u548cmatmul\u662f\u77e9\u9635\u76f8\u4e58 dot\u662f\u70b9\u4e58","text":"import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = tensor1 * tensor2\nprint(result) # Output: tensor([4, 10, 18])\n
import torch\ntensor1 = torch.tensor([[1, 2], [3, 4]])\ntensor2 = torch.tensor([[5, 6], [7, 8]])\nresult = tensor1 @ tensor2\nprint(result) # Output: tensor([[19, 22], [43, 50]])\n
import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = torch.dot(tensor1, tensor2)\nprint(result) # Output: tensor(32)\n
import torch\ntensor1 = torch.tensor([1, 2, 3])\ntensor2 = torch.tensor([4, 5, 6])\nresult = torch.dot(tensor1, tensor2)\nprint(result) # Output: tensor(32)\n
"},{"location":"DL/Python/pytorch/#to-train-the-model-with-gpu","title":"To train the model with GPU","text":"import torch\n# Step 1: Check for GPU availability\nif torch.cuda.is_available():\ndevice = torch.device('cuda')\nelse:\ndevice = torch.device('cpu')\n# Step 2: Move the model and data to the GPU\nmodel = YourModel().to(device)\ndata = YourData().to(device)\n# Step 3: Update the computation on the GPU\nmodel.to(device)\ndata = data.to(device)\n# Step 4: Perform training and inference\nfor epoch in range(num_epochs):\n# Training loop\nfor batch in data_loader:\ninputs, labels = batch\ninputs = inputs.to(device)\nlabels = labels.to(device)\n# Perform forward and backward pass, update model parameters\n# Inference\nwith torch.no_grad():\nfor batch in validation_data_loader:\ninputs, labels = batch\ninputs = inputs.to(device)\nlabels = labels.to(device)\n# Perform forward pass for evaluation\n
"},{"location":"DL/Python/setup_pack/","title":"Python Setup Packages","text":"\u7f16\u5199setup.py\u6587\u4ef6\u662f\u4e3a\u4e86\u4f7f\u7528Python\u7684setuptools\u6784\u5efa\u5b89\u88c5\u81ea\u5df1\u7684Python\u5305\u3002 \u4e00\u4e2asetup.py\u6587\u4ef6\u5e94\u5f53\u653e\u5728\u5305\u4ee3\u7801\u76ee\u5f55\u4e0b\u3002\u4f8b\u5982\u5305\u4ee3\u7801\u76ee\u5f55\u4e3a
your_package_name/\n__init__.py\nmodule1.py\nmodule2.py\nsetup.py\n
\u5176\u4e2dsetup.py\u7684\u5199\u6cd5\u662f from setuptools import setup\nsetup(\nname='YourPackageName',\nversion='1.0',\nauthor='Your Name',\nauthor_email='your@email.com',\ndescription='Description of your package',\npackages=['your_package_name'], # \u5305\u7684\u76ee\u5f55\u5217\u8868\u3002\u5982\u679c\u6709\u591a\u4e2a\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528find_packages()\u67e5\u627e\ninstall_requires=[ # \u8fd9\u4e9b\u4f9d\u8d56\u5c06\u81ea\u52a8\u5b89\u88c5 \n'dependency1',\n'dependency2',\n],\n)\n
\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0c\u5e94\u5f53\u5728\u547d\u4ee4\u884c\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f\u8fd0\u884c\u6253\u5305 python setup.py sdist bdist_wheel\n
\u7528\u5982\u4e0b\u65b9\u5f0f\u5b89\u88c5 pip install dist/YourPackageName-1.0.tar.gz\n
"},{"location":"DL/Terminal/anaconda/","title":"Anaconda \u5e38\u7528\u547d\u4ee4","text":""},{"location":"DL/Terminal/anaconda/#_1","title":"\u521b\u5efa\u73af\u5883","text":"conda create --name [ENV_NAME] python==3.9\n
"},{"location":"DL/Terminal/anaconda/#_2","title":"\u5220\u9664\u73af\u5883","text":" conda remove -n [ENV_NAME] --all\n
"},{"location":"DL/Terminal/anaconda/#_3","title":"\u67e5\u770b\u73b0\u5b58\u865a\u62df\u73af\u5883","text":"conda env list\n
"},{"location":"DL/Terminal/anaconda/#_4","title":"\u67e5\u770b\u76ee\u524d\u73af\u5883\u5df2\u5b89\u88c5\u5305","text":"conda list\n
"},{"location":"DL/Terminal/anaconda/#_5","title":"\u6253\u5f00\u73af\u5883","text":" conda activate [ENV_NAME]\n
"},{"location":"DL/Terminal/anaconda/#_6","title":"\u5173\u95ed\u73af\u5883","text":"conda deactivate\n
"},{"location":"DL/Terminal/anaconda/#_7","title":"\u5220\u9664\u73af\u5883\u4e2d\u7684\u67d0\u4e2a\u5305","text":"conda remove --name [ENV_NAME] [PACK_NAME]\n
Update specific package:
conda update [PACK_NAME]\n
Update all packages in the current environment:
conda update --all\n
Update all packages in the current environment:
conda update -n myenv --all\n
Update Python:
conda update python\n
Update conda itself:
conda update conda\n
TODO \u5728\u5199\u4e86\u8fd9\u4e2a\u771f\u7684\u5728\u5199\u4e86
\u5220\u9664\u6587\u4ef6
rm [FILENAME]\n
\u5220\u9664\u76ee\u5f55
rm -rf [PATH]\n
"},{"location":"DL/Terminal/pytorch_terminal/","title":"Pytorch \u547d\u4ee4\u884c\u547d\u4ee4","text":""},{"location":"DL/Terminal/pytorch_terminal/#install","title":"install","text":"(MacOS, conda, no GPU or CUDA)
conda install pytorch torchvision torchaudio -c pytorch\n
"},{"location":"DL/Terminal/pytorch_terminal/#20220112-cannot-import-name-field-from-torchtext","title":"2022/01/12 cannot import name \u2018Field\u2019 from \u2018torchtext\u2019","text":"\u65b0\u7248torchtext\u628afield\u7c7b\u5220\u4e86\uff0c\u2019.legacy\u2019\u4e5f\u68c0\u6d4b\u4e0d\u5230\uff0c\u7528\u7248\u672c\u56de\u9000
pip --default-timeout=100 install torchtext==0.10.0\n
"},{"location":"DL/Terminal/tmux/","title":"tmux","text":"install
git clone https://github.com/tmux/tmux.git\ncd tmux\nsh autogen.sh\n./configure && make\n
# Ubuntu \u6216 Debian\n$ sudo apt-get install tmux\n# CentOS \u6216 Fedora\n$ sudo yum install tmux\n\n# Mac\n$ brew install tmux\n
\u5f00\u542f\u65b0\u8fdb\u7a0b\u7684\u901a\u7528\u547d\u4ee4
tmux new-session -d -s my_session \\; send-keys \"<command>\" Enter\n
\u4e0a\u4f20\u6587\u4ef6\u7528ssh\u5230\u670d\u52a1\u5668
tmux new-session -d -s my_session \\; send-keys \"rsync filename username@ip_address:/home/username\" Enter\n
\u8fd0\u884cpython\u811a\u672c
tmux new-session -d -s <session name> \\; send-keys \"python3 <program name>.py\" Enter\n
\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b
tmux ls\n
\u6740\u6b7b\u8fdb\u7a0b
tmux kill-session -t <session name>\n
\u901a\u8fc7\u91cd\u5b9a\u5411\u8f93\u51fa\u5b9e\u73b0tmux\u4f1a\u8bdd\u4e2d\u4e0e\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u901a\u4fe1\u3002
tmux new-session -d -s <session name> \\; send-keys \"python3 <program name>.py > output.txt\" Enter\n
\u67e5\u770boutput.txt\u7684\u5185\u5bb9
cat output.txt\n
\u5b9e\u65f6\u76d1\u6d4b\u6587\u4ef6\u7684\u53d8\u5316 \u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u968f\u65f6\u663e\u793aoutput.txt\u7684\u5185\u5bb9
tail -f output.txt\n
ssh username@server_address tmux ls\n
ssh username@server_address tmux ls -t <session_name>\n
"},{"location":"Ling/","title":"\u7d22\u5f15","text":"\u672c\u4e13\u680f\u5305\u542b\u8bed\u8a00\u5b66\u7b14\u8bb0\uff0c\u76ee\u524d\u5df2\u5b8c\u6210\u4ee5\u4e0b\u5185\u5bb9
Aug. 25th. 2023
This talk aims both to provide an introduction to the subject Philosophy of Language (a similar subject with semantics and pragmatics, according to its definition; PoL hereafter), and give a summary on the recent ongoing discussion on the linguistics concepts in NLP (e.g. \"meaning\", \"understanding\", \"reasoning\", \"grounding\").
"},{"location":"Ling/pol_en_todo/#a-preview-of-this-talk","title":"A Preview of This Talk","text":"1st 40min: History of philosophy of language 2nd 40min: Recent papers and discussions on PoL topics in NLP 3rd 10min: Discussion on take-away
"},{"location":"Ling/pol_en_todo/#the-location-of-pol-on-the-academic-coordinate","title":"The Location of PoL on the Academic Coordinate","text":"Before we start this talk, we will first provide a brief definition of the term Philosophy of Language in our talk here. The PoL concerns mainly the two following questions, (i) The relationship between the natural language and the world, (ii) The relationship between the human languages and their meaning. Chen (2003) believes that the PoL and the linguistics are two different subjects. He suggests that the linguistics is the study of language rules and patterns and the application of them, while the PoL pays more attention on the more abstract and essential features of the human language (e.g. its relation to the cognition). The author of this talk believes, according to the definition of PoL, it is a subject that closely involves the semantics and pragmatics branches in linguistics. However the PoL and linguistics overlap or not, it is commonly believed that the subject PoL was born in the 1920s, when the linguistic turn was put on stage in the European philosophy.
"},{"location":"Ling/pol_en_todo/#history-of-pol","title":"History of PoL","text":"Now we will dive into the history of PoL. This section is parted \"person by person\". It is noticed that \"person-by-person\" is a common structure of most of the philosophy history, as most of the philosophy progresses are propelled by giants instead of the common people.
"},{"location":"Ling/pol_en_todo/#gottfried-wilhelm-leibniz","title":"Gottfried Wilhelm Leibniz","text":"The main contribution of Leibniz is
"},{"location":"Ling/pol_en_todo/#ferdinand-de-saussure","title":"Ferdinand de Saussure","text":""},{"location":"Ling/pol_en_todo/#friedrich-ludwig-gottlob-frege","title":"Friedrich Ludwig Gottlob Frege","text":""},{"location":"Ling/pol_en_todo/#bertrand-russell","title":"Bertrand Russell","text":"Bertrand Russell is a pure logician.
"},{"location":"Ling/pol_en_todo/#ludwig-wittgenstein","title":"Ludwig Wittgenstein","text":""},{"location":"Ling/pol_en_todo/#noam-chomsky","title":"Noam Chomsky","text":""},{"location":"Ling/pol_zh/","title":"Philosophy of Language \u8bed\u8a00\u54f2\u5b66","text":"Nov. 9th. 2022
"},{"location":"Ling/pol_zh/#talk","title":"\u8fd9\u6b21talk\u4f1a\u8bb2\u4ec0\u4e48","text":"\u2705\u00a0\u4ecb\u7ecd\u8bed\u8a00\u54f2\u5b66\u7684\u601d\u6f6e\u6d41\u53d8\u5386\u7a0b\uff0c\u4ecb\u7ecd\u8bed\u8a00\u4e0a\u7684\u5b9e\u9a8c\u601d\u60f3\u5b9e\u9a8c\uff0c\u8ba8\u8bba\u4e00\u4e9b\u8bed\u8a00\u5b66\u3001\u8ba4\u77e5\u3001\u903b\u8f91\u548c\u54f2\u5b66\u7684\u5173\u8054
"},{"location":"Ling/pol_zh/#pol","title":"PoL","text":"\u8bed\u8a00\u54f2\u5b66\u7684\u57fa\u672c\u95ee\u9898\uff1a 1. \u8bed\u8a00\u548c\u4e16\u754c\u7684\u5173\u7cfb 2. \u8bed\u8a00\u6216\u8bed\u8bcd\u7684\u610f\u4e49\u95ee\u9898
\u8bed\u8a00\u54f2\u5b66\u548c\u8bed\u8a00\u5b66 \u8bed\u8a00\u5b66\u548c\u8bed\u8a00\u54f2\u5b66\u7684\u8054\u7cfb\u7d27\u5bc6\uff0c\u4f46\u662f\u662f\u4e24\u95e8\u5b66\u79d1\u3002
20\u4e16\u7eaa\u54f2\u5b66\u4e0a\u53d1\u751f\u4e86\u8bed\u8a00\u8f6c\u5411\uff0c\u8fd9\u4e5f\u662f\u73b0\u4ee3\u8bed\u8a00\u5b66\u5f62\u6210\u7684\u65f6\u5019\u3002
\u8bed\u8a00\u5b66\u662f\u5bf9\u8bed\u8a00\u89c4\u5f8b\u548c\u8fd9\u4e9b\u89c4\u5f8b\u7684\u5e94\u7528\u7684\u7814\u7a76\uff0c\u8bed\u8a00\u54f2\u5b66\u66f4\u5173\u5fc3\u8bed\u8a00\u66f4\u672c\u8d28\u66f4\u62bd\u8c61\u7684\u610f\u4e49\u3002
"},{"location":"Ling/pol_zh/#history-of-pol","title":"History of PoL","text":"\u83b1\u5e03\u5c3c\u8328\uff1a\u63d0\u51fa\u903b\u8f91\u8bed\u8a00\uff0c\u7b80\u5386\u4eba\u5de5\u8bed\u8a00\u7684\u52aa\u529b
\u5f3a\u8c03\u81ea\u7136\u8bed\u8a00\u4f9d\u8d56\u4e8e\u77e5\u8bc6\uff0c\u56e0\u6b64\u5206\u6709\u77e5\u89c9\u7684\u6a21\u7cca\u3001\u6b67\u4e49\u7b49\u79cd\u79cd\u7f3a\u9677\u3002\u81ea\u7136\u8bed\u8a00\u4e0d\u662f\u63cf\u8ff0\u5ba2\u89c2\u4e8b\u7269\u7684\u6700\u4f73\u5de5\u5177\uff0c\u4e3a\u4e86\u63a2\u7a76\u771f\u7406\uff0c\u5fc5\u987b\u5efa\u7acb\u4e00\u4e2a\u7531\u666e\u904d\u7b26\u53f7\u7ec4\u6210\u7684\u66f4\u4e3a\u6e05\u695a\u7684\u7b26\u53f7\u4f53\u7cfb\u3002\u8fd9\u79cd\u52aa\u529b\u5728\u6570\u5b66\u65b9\u9762\u662f\u5353\u6709\u6210\u6548\u7684\uff0c\u6bd4\u5982\u5fae\u79ef\u5206\u7b26\u53f7\u3002
\u7d22\u7eea\u5c14\uff1a \u7d22\u7eea\u5c14\u6700\u5927\u7684\u5f71\u54cd\u662f\u300a\u666e\u901a\u8bed\u8a00\u5b66\u300b\u3002\u6211\u4eec\u4e00\u822c\u8ba4\u4e3a\u7d22\u7eea\u5c14\u662f\u4e00\u4f4d\u8bed\u8a00\u5b66\u5bb6\uff0c\u4f46\u662f\u4ed6\u5728\u8fd9\u672c\u4e66\u4e2d\u63d0\u51fa\u7684\u201c\u80fd\u6307\u201d\u4e0e\u201c\u6240\u6307\u201d\u7406\u8bba\uff0c\u662f\u54f2\u5b66\u91cc\u7684\u7b26\u53f7\u5b66\u7684\u5f00\u7aef\u3002
\u8bed\u8a00\u662f\u7528\u58f0\u97f3\u8868\u8fbe\u601d\u60f3\u7684\u7b26\u53f7\u7cfb\u7edf\uff0c\u7b26\u53f7\u662f\u7528\u4ee5\u8868\u793a\u8005\u548c\u88ab\u8868\u793a\u8005\u7684\u7ed3\u5408\u3002
\u6211\u4eec\u4f1a\u8bf4\uff0c\u58f0\u97f3\u672c\u8eab\u4e0d\u80fd\u65bd\u6307\uff0c\u53ea\u6709\u5904\u5728\u67d0\u79cd\u7279\u5b9a\u5173\u7cfb\u4e2d\uff08\u8bed\u8a00\u5b9a\u4e49\u4e86\u58f0\u97f3\u548c\u5b9e\u4f53\u4e4b\u95f4\u7684\u5173\u7cfb\uff09\uff0c\u58f0\u97f3\u624d\u6709\u4e86\u610f\u4e49\u3002
\u4efb\u610f\u6027\u539f\u5219\u662f\uff0c\u5982\u6b64\u8fd9\u822c\u7684\u65bd\u6307\u548c\u5982\u6b64\u8fd9\u822c\u7684\u6240\u6307\u7ed3\u5408\u800c\u6210\u7684\u4e00\u4e2a\u7b26\u53f7\uff0c\u662f\u4efb\u610f\u7684\u3002eg. \u989c\u8272\u4e0e\u989c\u8272\u8bcd\u7684\u8054\u7ed3\u662f\u4efb\u610f\u7684\uff0c\u989c\u8272\u7684\u754c\u9650\u4e0e\u989c\u8272\u8bcd\u7684\u8054\u7ed3\u4e5f\u662f\u4efb\u610f\u7684\u3002
\"\u7eff\"\u4e0d\u4ec5\u548c\u7eff\u989c\u8272\u76f8\u8fde\uff0c\u800c\u4e14\u548c\u201c\u84dd\u201d\u201c\u9752\u201d\u7b49\u8bed\u8bcd\u76f8\u8fde\u3002\n\u5982\u679c\u6ca1\u6709\u201c\u84dd\u201d\u201c\u9752\u201d\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u77e5\u9053\u201c\u7eff\u201d\u6240\u754c\u5b9a\u7684\u989c\u8272\u8303\u56f4\u3002\n\n\u201c\u4e03\u8272\u5f69\u8679\u201d\n\u65e5\u8bed\u4e0d\u533a\u5206\u201c\u84dd\u201d\u548c\u201c\u7eff\u201d\uff0c\u53ea\u6709\u4e00\u4e2a\u5355\u8bcd\u201c\u9752\u201d\uff08aoi\uff09\uff0c\u65e5\u8bed\u6bcd\u8bed\u8005\u5728\u9274\u522b\u84dd\u8272\u548c\u7eff\u8272\u65f6\u53cd\u5e94\u65f6\u9ad8\u4e8e\u82f1\u8bed\u6bcd\u8bed\u8005\u3002\n\u4e00\u79cd\u5317\u6b27\u8bed\u8a00\u6709\u4e03\u79cd\u84dd\u8272\u7684\u540d\u79f0\u3002\n
\u6211\u4eec\u4e60\u60ef\u628a\u8bed\u8bcd\u548c\u60c5\u5883\u7684\u8054\u7cfb\u79f0\u4f5c\u7eb5\u5750\u6807\u6216\u8bed\u5883\u5750\u6807\uff0c\u628a\u8bed\u8bcd\u4e4b\u95f4\u7684\u8054\u7cfb\u79f0\u4f5c\u6a2a\u5750\u6807\u548c\u903b\u8f91\u5750\u6807\u3002
eg. \u5b8c\u5f62\u586b\u7a7a\u9898
eg. \u6570\u636e\u5e93\u5173\u7cfb\u6a21\u578b\u7684\u5c5e\u6027\u3001\u5143\u7ec4
\u975e\u5e38\u6709\u8da3\uff0c\u7d22\u7eea\u5c14\u5199\u8fd9\u672c\u8bed\u8a00\u5b66\u6559\u6750\u65f6\uff0c\u4e16\u754c\u4e0a\u5e76\u6ca1\u6709\u7b26\u53f7\u5b66\u8fd9\u4e2a\u5b66\u79d1\u3002\u5728\u4ed6\u63d0\u51fa\u201c\u80fd\u6307\u201d\u201d\u6240\u6307\u201c\u8fd9\u4e2a\u6982\u5ff5\u540e\uff0c\u7b26\u53f7\u5b66\u5728\u4ed6\u201d\u80fd\u6307\u201c\u5728\u201d\u6240\u6307\u201c\u7684\u94fe\u6761\u4e0a\u6ed1\u52a8\u8fd9\u4e00\u8bba\u65ad\u7684\u57fa\u7840\u4e0a\u8bde\u751f\uff0c\u5e76\u81f3\u4eca\u6210\u4e3a\u6cd5\u56fd\u54f2\u5b66\u7684\u4e00\u4e2a\u91cd\u8981\u95ee\u9898\u3002
\u5f17\u96f7\u683c\uff1a
\u5f17\u96f7\u683c\u662f\u516c\u8ba4\u7684\u5206\u6790\u54f2\u5b66\u3001\u8bed\u8a00\u54f2\u5b66\u548c\u73b0\u4ee3\u6570\u7406\u903b\u8f91\u7684\u5f00\u521b\u8005\u3002
\u300a\u6982\u5ff5\u6587\u5b57\uff1a\u4e00\u79cd\u6a21\u4eff\u7b97\u672f\u8bed\u8a00\u6784\u9020\u7684\u7eaf\u601d\u7ef4\u7684\u5f62\u5f0f\u8bed\u8a00\u300b\u4e3b\u8981\u5de5\u4f5c\u662f\uff0c\u8bbe\u8ba1\u4e86\u4e00\u5957\u4eba\u5de5\u7b26\u53f7\u7cfb\u7edf\uff0c\u6392\u9664\u4e86\u81ea\u7136\u8bed\u8a00\u4e2d\u4fee\u8f9e\u4e4b\u7c7b\u7684\u4e1c\u897f\uff0c\u4e13\u6ce8\u4e8e\u6982\u5ff5\u672c\u8eab\u548c\u6982\u5ff5\u4e4b\u95f4\u7684\u8054\u7cfb\uff0c\u56e0\u6b64\uff0c\u5b83\u5c06\u6392\u9664\u81ea\u7136\u8bed\u8a00\u7684\u6a21\u7cca\u6027\u548c\u4e0d\u786e\u5b9a\u6027\u3002\u7528\u8fd9\u5957\u7b26\u53f7\u7cfb\u7edf\u6765\u91cd\u65b0\u8868\u8ff0\u7b97\u672f\u7684\u57fa\u672c\u6982\u5ff5\u548c\u63a8\u7406\u89c4\u5219\uff0c\u660e\u786e\u6240\u6709\u63a8\u7406\u7684\u524d\u63d0\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u8bc1\u660e\u4e2d\u5404\u4e2a\u547d\u9898\u95f4\u7684\u6240\u6709\u63a8\u7406\u89c4\u5219\uff0c\u4f7f\u63a8\u7406\u4e0d\u518d\u57fa\u4e8e\u76f4\u89c9\uff0c\u4e5f\u6ca1\u6709\u8df3\u8dc3\u548c\u8131\u8282\u3002
\u5bf9\u8bed\u8a00\u54f2\u5b66\u5f71\u54cd\u6700\u6df1\u7684\u662f\u4ed6\u5728\u300a\u7b97\u672f\u57fa\u7840\u300b\u4e2d\u63d0\u51fa\u7684\u4e09\u6761\u8457\u540d\u539f\u5219\uff1a
\u4e24\u4e2a\u601d\u7ef4\u5b9e\u9a8c\uff1a
\u6307\u79f0\u76f8\u540c\u800c\u610f\u4e49\u4e0d\u540c\u7684\u8bcd
\u201c\u542f\u660e\u661f\u201d\u548c\u201c\u957f\u5e9a\u661f\u201d\u662f\u540c\u4e00\u9897\u884c\u661f\u2014\u2014\u2014\u2014\u91d1\u661f\u3002\n\u4f46\u662f\u4e24\u4e2a\u540d\u8bcd\u7684\u610f\u4e49\u4e0d\u540c\uff0c\u5927\u591a\u6570\u65f6\u5019\u4e0d\u80fd\u66ff\u6362\u3002\n\u201c\u4ed6\u5929\u8fd8\u6ca1\u4eae\u5c31\u8d77\u8eab\uff0c\u8fce\u7740\u542f\u660e\u661f\u5411\u4e1c\u8d70\u53bb\u3002\u201d\n
\u51fd\u5f0f\u7406\u8bba
\uff08 \uff09\u662f\u4e2d\u56fd\u7684\u9996\u90fd\n\uff08 \uff09= \"\u4f26\u6566\"\u3001\"\u5317\u4eac\"\n\u53ea\u6709\u586b\u5165\u5317\u4eac\u7684\u65f6\u5019\u624d\u662f\u771f\u547d\u9898\n
\u7f57\u7d20\uff1a\u903b\u8f91
\u6df1\u5165\u4e13\u540d\u548c\u901a\u540d\u3001\u6096\u8bba\u3001\u6392\u4e2d\u5f8b\u3002
\u7ef4\u7279\u6839\u65af\u5766\uff1a
\u524d\u671f\u601d\u60f3\u300a\u903b\u8f91\u54f2\u5b66\u8bba\u300b
\u201c\u4e16\u754c\u662f\u4e8b\u5b9e\u7684\u7efc\u5408\u201d\uff1a\u201c\u53f8\u9a6c\u5149\u662f\u5510\u671d\u4eba\u201d\u7b26\u5408\u903b\u8f91\uff0c\u4f46\u4e0d\u7b26\u5408\u4e8b\u5b9e\u3002
\u56fe\u50cf\u8bba
\u8bed\u8a00\u662f\u547d\u9898\u7684\u603b\u548c\u800c\u4e0d\u662f\u540d\u79f0\u7684\u603b\u548c\u3002
\u4eba\u5728\u4ea4\u6d41\u601d\u60f3/\u547d\u9898\u65f6\uff0c\u4ea4\u6d41\u7684\u662f\u8111\u4e2d\u7684\u56fe\u50cf\u3002
\u4ed6\u7684\u524d\u671f\u601d\u60f3\u542f\u53d1\u4e86\u7ef4\u4e5f\u7eb3\u5b66\u6d3e\uff1a\u4eba\u5de5\u8bed\u8a00\uff0c\u903b\u8f91\u8bed\u8a00
\u5341\u4e5d\u4e16\u7eaa\u672b\u4ee5\u6765\u4eba\u5de5\u8bed\u8a00\u7684\u5c1d\u8bd5\uff1a\u201c\u4e16\u754c\u8bed\uff08Esperanto\uff09\u201d\uff0c\u4e18\u5409\u5c14\u63a8\u5d07\u7684\u57fa\u672c\u82f1\u8bed\uff0c\u81ea\u7136\u8bed\u8a00\u4e2d\u5bf9\u201c\u5973\u4eba\u201d\u201c\u5973\u6027\u201d\u201c\u5973\u58eb\u201d\u201c\u5987\u5973\u201d\u8fd9\u6837\u7684\u6307\u79f0\u7684\u89c4\u8303\u5c1d\u8bd5\u3002
\u540e\u671f\u601d\u60f3\u300a\u54f2\u5b66\u7814\u7a76\u300b
\u8bed\u8a00\u6e38\u620f\uff08Sprachspiel\uff09
\u8bed\u8a00\u7684\u529f\u80fd\u7684\u672c\u8d28\uff1a\u4e00\u65b9\u558a\u51fa\u8bed\u8bcd\uff0c\u53e6\u4e00\u65b9\u4f9d\u7167\u8fd9\u4e9b\u8bed\u8bcd\u6765\u884c\u52a8\u3002
\u8001\u5e08\u6307\u7740\u77f3\u5934\u8bf4\u201c\u77f3\u5934\u201d\uff0c\u5b66\u751f\u8ddf\u7740\u8bf4\u201c\u77f3\u5934\u201d\u3002\n
\u4e22\u624b\u7ee2\u65f6\u5531\u7740\u201c\u8f7b\u8f7b\u5730\u653e\u5728\u5c0f\u670b\u53cb\u7684\u8eab\u540e\u201d\uff0c\u628a\u624b\u7ee2\u653e\u5728\u5c0f\u670b\u53cb\u7684\u8eab\u540e\n
\u4e0e\u524d\u671f\u56fe\u50cf\u7406\u8bba\u7684\u5bf9\u6bd4\uff1a\u5728\u56fe\u50cf\u7406\u8bba\u4e2d\uff0c\u8bed\u8a00\u4ece\u6839\u672c\u4e0a\u662f\u4e00\u79cd\u53cd\u6620\uff1b\u5728\u8bed\u8a00\u6e38\u620f\u8bf4\u4e2d\uff0c\u8bed\u8a00\u9996\u5148\u662f\u4e00\u79cd\u6d3b\u52a8\u3002
\u610f\u4e49\u6765\u6e90\u4e8e\u4f7f\u7528\u3002
\u6211\u4eec\u5173\u5fc3\u201c\u9524\u5b50\u201d\u662f\u4ec0\u4e48\u65f6\uff0c\n\u5173\u5fc3\u7684\u662f\u201c\u4f7f\u7528\u4e00\u628a\u9524\u5b50\u201d\uff0c\n\u800c\u4e0d\u662f\u201c\u9524\u5b50\u610f\u5473\u7740\u2026\u2026\u201d\n\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u4e5f\u6b63\u662f\u4ece\u201c\u4f7f\u7528\u4e00\u628a\u9524\u5b50\u201d\u6765\u5b9a\u4e49\u9524\u5b50\n
\u5982\u4f55\u533a\u5206\u201c\u4f7f\u7528\u201d\u201c\u6709\u7528\u201d\u201c\u5229\u7528\u201d\uff1f\n\u5728\u4e00\u4e9b\u60c5\u5883\u4e2d\u80fd\u7528\uff0c\u5728\u4e00\u4e9b\u60c5\u5883\u4e2d\u4e0d\u80fd\u7528\u3002\n
\u8bed\u8a00\u6e38\u620f\u7684\u7c7b\u522b
\u5bb6\u65cf\u76f8\u4f3c\u7406\u8bba\uff08Familien\u00e4hnlichkeiten\uff09
\u201c\u4e00\u4e2a\u5bb6\u65cf\u7684\u6709\u4e9b\u6210\u5458\u6709\u4e00\u6837\u7684\u9f3b\u5b50\uff0c\u53e6\u4e00\u4e9b\u6709\u4e00\u6837\u7684\u7709\u6bdb\uff0c\u8fd8\u6709\u4e00\u4e9b\u6709\u4e00\u6837\u7684\u6b65\u6001\uff1b\u8fd9\u4e9b\u76f8\u4f3c\u4e4b\u5904\u4ea4\u53c9\u91cd\u53e0\u3002\u201c
\u5185\u6db5\uff1a\u4e00\u4e2a\u6982\u5ff5\u7684\u5b9a\u4e49
\u5916\u5ef6\uff1a\u4e00\u4e2a\u6982\u5ff5\u5305\u542b\u7684\u4e0b\u5c5e\u6982\u5ff5\u7684\u8303\u56f4
\u901a\u540d\u7684\u4e0b\u5c5e\u8bcd\uff0c\u5404\u79cd\u4e13\u540d\u4e4b\u95f4\u5e76\u6ca1\u6709\u4e25\u683c\u7684\u754c\u9650\uff0c\u4e00\u4e2a\u76f8\u4f3c\u53e6\u4e00\u4e2a\uff0c\u5206\u4eab\u4e0d\u540c\u7684\u5171\u540c\u7279\u5f81\u3002
\u751f\u6d3b\u5f62\u5f0f\uff08Lebens Form\uff09\uff1a\u5e38\u8bc6\u7684\u91cd\u8981\u6027
\u201c\u626b\u5e1a\u5728\u90a3\u91cc\u201d\u5df2\u7ecf\u8db3\u591f\u6e05\u6670\u3002\n\u201c\u626b\u5e1a\u628a\u548c\u626b\u5e1a\u5934\u5728\u90a3\u91cc\u201d\uff0c\u867d\u7136\u5206\u6790\u5f97\u66f4\u6e05\u695a\uff0c\u4f46\u5728\u4ea4\u9645\u4e2d\u8ba9\u4eba\u8d39\u89e3\u3002\n
\u4eff\u4f5b\u6211\u4eec\u53ea\u8981\u66f4\u591a\u8bf4\u4e00\u70b9\uff0c\u591a\u5206\u6790\u4e00\u70b9\uff0c\u4e8b\u60c5\u5c31\u4f1a\u66f4\u6e05\u695a\uff0c\u4eff\u4f5b\u6ca1\u6709\u4e00\u53e5\u8bdd\u672c\u8eab\u5c31\u662f\u8db3\u591f\u6e05\u695a\u7684\u3002
"},{"location":"Ling/pol_zh/#conclusion-of-agreements","title":"Conclusion of Agreements","text":"\u963f\u4f69\u5c14\u603b\u7ed3\u897f\u65b9\u54f2\u5b66\u7684\u53d1\u5c55\uff1a
\u53e4\u4ee3\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u672c\u4f53\u8bba\uff0c\u4ece\u8fd1\u4ee3\u5f00\u59cb\uff0c\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u8ba4\u8bc6\u8bba\uff0c\u523020\u4e16\u7eaa\uff0c\u54f2\u5b66\u6ce8\u91cd\u7684\u662f\u8bed\u8a00\u3002
\u672c\u4f53\u8bba\u7684\u95ee\u9898\uff1a\u4ec0\u4e48\u4e1c\u897f\u5b58\u5728\uff0c\u4ec0\u4e48\u662f\u5b9e\u5728\u7684\u57fa\u672c\u5b58\u5728\u5f62\u5f0f\u3002
\u8ba4\u8bc6\u8bba\u7684\u95ee\u9898\uff1a\u54ea\u4e9b\u4e1c\u897f\u662f\u6211\u4eec\u80fd\u8ba4\u8bc6\u7684\uff0c\u6211\u4eec\u662f\u600e\u6837\u8ba4\u8bc6\u8fd9\u4e9b\u4e1c\u897f\u7684\u3002
\u8bed\u8a00\u7684\u95ee\u9898\uff1a\u6211\u4eec\u5728\u4f55\u79cd\u610f\u4e49\u4e0a\u80fd\u591f\u8ba4\u8bc6\u5b58\u5728\u2014\u2014\u800c\u610f\u4e49\u7684\u9996\u8981\u8f7d\u4f53\u662f\u8bed\u8a00\u3002\u2192 Linguistic Turn
PoL\u7684\u5176\u5b83topic\uff1a 1. \u6307\u79f0\u4e0e\u5b9e\u4f53\uff0c\u8bed\u8a00\u4e0e\u610f\u4e49\u7684\u5173\u7cfb 2. \u901a\u540d\u4e0e\u4e13\u540d\uff0c\u8bcd\u4e49\u7684\u8303\u56f4 3. \u771f\u7406\u7406\u8bba 4. \u300a\u6211\u4eec\u8d56\u4ee5\u751f\u5b58\u7684\u9690\u55bb\u300b\uff1a\u9690\u55bb\u65e0\u5904\u4e0d\u5728\uff0c\u4e0d\u4ec5\u5b9a\u4e49\u4e2d\u7684\u201cxx\u662fxx\u201d\u662f\u9690\u55bb\uff0c\u6709\u65f6\u5355\u4e2a\u8bcd\u5c31\u662f\u4e00\u4e2a\u9690\u55bb\u3002
\u52a8\u8bcd\u662f\u9690\u55bb
\u65f6\u95f4\u5728\u6d41\u901d\u3002\n
\u4ecb\u8bcd\u662f\u9690\u55bb
I\u2019m feeling up today.\nHe is down.\n\u9ad8\u5174\u4e3a\u4e0a\uff0c\u60b2\u4f24\u4e3a\u4e0b\u3002\nWake up.\nHe fell asleep.\n\u6709\u610f\u8bc6\u4e3a\u4e0a\uff0c\u65e0\u610f\u8bc6\u4e3a\u4e0b\u3002\nHe fell ill.\nShe dropped dead.\n\u5065\u5eb7\u548c\u751f\u547d\u4e3a\u4e0a\uff0c\u75be\u75c5\u548c\u6b7b\u4ea1\u4e3a\u4e0b\u3002\nI have controlled over her.\nHe fell from power.\n\u63a7\u5236\u6216\u5f3a\u8feb\u4e3a\u4e0a\uff0c\u88ab\u63a7\u5236\u6216\u88ab\u5f3a\u8feb\u4e3a\u4e0b\u3002\nMy income rose last year.\nThe number of errors is low.\n\u66f4\u591a\u4e3a\u4e0a\uff0c\u66f4\u5c11\u4e3a\u4e0b\u3002\n
\u4e54\u59c6\u65af\u57fa\uff1a
\u7ed3\u6784\u4e3b\u4e49\u8bed\u8a00\u5b66\u5230\u8f6c\u6362\u751f\u6210\u8bed\u6cd5\u3002
\u8bed\u8a00\u5b66\u7684\u5de5\u4f5c\u4e0d\u5e94\u5f53\u662f\u641c\u96c6\u8bed\u8a00\u7d20\u6750\u52a0\u4ee5\u5f52\u7eb3\uff0c\u800c\u662f\u8981\u89e3\u91ca\u8bed\u8a00\u7684\u521b\u9020\u6027\u3002
CNF
S -> AB\nA -> AA | a\nB -> b | e\n
\u8f6c\u6362\u751f\u6210\u8bed\u6cd5\u89c4\u5219 \\(\\Sigma = \\{NP, Vp, T, N, Npsing, NPpl, Aux, V, C, M, En, S, Past, Af\\}\\)
S -> NP + VP\nVP -> Verb + NP\nNP -> Det + N\nVerb -> Aux + V\nDet -> the, a...\nN -> man, ball...\nAux -> will, can...\nV -> hit, see...\n
\u4f20\u7edf\uff08\u6210\u5206\uff09\u8bed\u6cd5\u89c4\u5219
1. \u4e3b + \u8c13\n2. \u4e3b + \u8c13 + \u5bbe\n3. \u4e3b + \u7cfb + \u8868\n4. \u4e3b + \u8c13 + \u5bbe + \u53cc\u5bbe\n5. \u4e3b + \u8c13 + \u5bbe + \u5bbe\u8865\n6. \u4e3b + \u8c13 + \u5e76\u5217\u5bbe\n\n...\n
\u300a\u53e5\u6cd5\u7ed3\u6784\u300b\uff081957\uff09\u6838\u5fc3\u53e5\u548c\u8f6c\u6362\u6982\u5ff5\u3002
\u751f\u6210\u6b65\u9aa4 1. \u751f\u6210\u6838\u5fc3\u53e5\u3002
S -> X1 | X2 | ... Xn\n
\u8f6c\u6362\u7ed3\u6784\uff08\u66ff\u6362\u3001\u7701\u7565\u3001\u6dfb\u52a0\u3001\u6362\u4f4d\uff09\u3002
X1 -> Y1Z1 | ...\n...\n
\u6dfb\u52a0\u5f62\u6001\u97f3\u4f4d\u89c4\u5219\u3002
Z1 -> W1\n...\nZn -> Wn\n
\u8f6c\u6362\uff1a\u6574\u4e2a\u8f6c\u6362\u751f\u6210\u8fc7\u7a0b\u53ef\u4ee5\u5206\u4e3a\u4e09\u4e2a\u6b65\u9aa4
\u6df1\u5c42\u7ed3\u6784\u548c\u8868\u5c42\u7ed3\u6784
\u4e54\u59c6\u65af\u57fa\u8bed\u6cd5\u4f53\u7cfb\u4e2d\uff0c\u6307\u53e5\u5b50\u751f\u6210\u8fc7\u7a0b\u4e2d\u7279\u5b9a\u9636\u6bb5\u6240\u91c7\u7528\u7684\u4e00\u79cd\u7279\u6b8a\u64cd\u4f5c\u624b\u6bb5\u6216\u89c4\u5219\u3002\u6df1\u5c42\u7ed3\u6784\u662f\u5b83\u7684\u8f93\u5165\uff0c\u8868\u5c42\u7ed3\u6784\u662f\u5b83\u7684\u8f93\u51fa\u3002
\u6709\u7684\u53e5\u5b50\u8868\u5c42\u7ed3\u6784\u4e0d\u540c\uff0c\u6df1\u5c42\u7ed3\u6784\u76f8\u4f3c\u3002\u901a\u8fc7\u8f6c\u6362\u64cd\u4f5c\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002
\u6709\u7684\u53e5\u5b50\u6df1\u5c42\u7ed3\u6784\u4e0d\u540c\uff0c\u8868\u5c42\u7ed3\u6784\u76f8\u4f3c\u3002\u901a\u8fc7\u8f6c\u6362\u64cd\u4f5c\u4e0d\u80fd\u76f8\u4e92\u8f6c\u5316\u3002
\u4e3a\u4ec0\u4e48\u4eca\u5929\u6211\u4eec\u8981\u8c08\u8bed\u8a00\u54f2\u5b66\uff1f
\u9648\u5609\u6620\u8001\u5e08\uff1a\u79d1\u5b66\u662f\u4e00\u4e2a\u4e25\u5bc6\u7684\u6574\u6d01\u7684\u4f53\u7cfb\uff0c\u539f\u56e0\u662f\u5b83\u628a\u6240\u6709\u6df7\u6c8c\u7684\u65e0\u6cd5\u89e3\u51b3\u7684\u95ee\u9898\u629b\u5728\u4e86\u8fd9\u4e2a\u4f53\u7cfb\u4e4b\u5916\u3002[\u300a\u8d70\u51fa\u552f\u4e00\u771f\u7406\u89c2\u300b\uff0c2020]
\u6240\u4ee5\u54f2\u5b66\u7684\u95ee\u9898\u662f\u7814\u7a76\u88ab\u79d1\u5b66\u6254\u51fa\u53bb\u7684\u6df7\u6c8c\u3002
\u8bed\u8a00\u54f2\u5b66\u5c31\u50cf\u201c\u5165\u4fb5\u7684\u5b9e\u5728\u754c\u201d\uff0c\u201c\u8fb9\u754c\u7684\u6d4b\u8bd5\u70b9\u201d\u3002
"},{"location":"Ling/pol_zh/#recommended-reading","title":"Recommended Reading","text":"\u300a\u8bed\u8a00\u54f2\u5b66\u300b\u9648\u5609\u6620
\u300a\u666e\u901a\u8bed\u8a00\u5b66\u300b\u7d22\u7eea\u5c14
\u300a\u903b\u8f91\u54f2\u5b66\u8bba\u300b\u7ef4\u7279\u6839\u65af\u5766
\u300a\u54f2\u5b66\u7814\u7a76\u300b\u7ef4\u7279\u6839\u65af\u5766
\u300a\u6211\u4eec\u8d56\u4ee5\u751f\u5b58\u7684\u9690\u55bb\u300b\u4e54\u6cbb\u00b7\u83b1\u8003\u592b
\u300a\u5fc3\u667a\u3001\u8bed\u8a00\u548c\u673a\u5668\u300b\u5f90\u82f1\u747e
"},{"location":"Ling/pol_zh/#_1","title":"\u8ba8\u8bba","text":"\u662f\u5426\u6240\u6709\u6ca1\u6709\u7528\u8bed\u8a00\u8868\u8fbe\u7684\u77e5\u8bc6\uff0c\u90fd\u53ef\u4ee5\u88ab\u7528\u8bed\u8a00\u8868\u8fbe\uff1f\uff08not NP or NP-hard\uff09
\u53ea\u5b66\u4e60\u8bed\u8a00\u662f\u5426\u80fd\u6a21\u62df\u4eba\u7684\u667a\u80fd\u6c34\u5e73\uff1f
\u6a21\u578b\u662f\u5426\u9700\u8981\u5e94\u5bf9\u6240\u6709\u7684\u5f02\u5e38\u60c5\u51b5/\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u672c\u8eab\u8981\u4e0e\u4eba\u7c7b\u8bed\u8a00\u6709\u6240\u533a\u522b
"},{"location":"Ling/Phonetics/reduction/","title":"Reduction of Intentionalverb+prep.
","text":""},{"location":"Ling/Phonetics/reduction/#introduction","title":"Introduction","text":"We will introduce the reductions of \u201cwanna\u201d, \u201cgonna\u201d, \u201cgotta\u201d, explain their reasons and provide a in several AmE dialects. Our inspiration for choosing this topic is from our watching television programs. Thus we will first show several pieces of video clips to get you familiar about our topic.
An interesting fact of this phenomenon: It is focused in bias analysis in hate speech detection task. A reduced form is 20%~30% more likely to be classified as hate speech as it is considered more related to African American English. [9]
"},{"location":"Ling/Phonetics/reduction/#video-clip-examples","title":"Video Clip Examples\u2b50","text":""},{"location":"Ling/Phonetics/reduction/#theory","title":"Theory","text":"In the following section, we will give a theoretical analysis of the phenomenon we found.
"},{"location":"Ling/Phonetics/reduction/#relevant-studies","title":"Relevant Studies","text":"[1]Patterns of Function Words Reduction
[2]Wanna Contraction and prosodic boundary\u2b50
Method: Case study
sentense-final postion: strong form.
a. I want to (wanna) dance//with somebody.5 \nb. I don\u2018t want to (*wanna)//.\n
\u201cwanna\u201d contraction to be one way of disambiguating the sentence
[3]Multiple Spell-Out and Contraction at the Syntax-Phonology Interface
[4]Frequency and Category Factors in the Reduction and Assimilation of Function Words: EPG and Acoustic Measures
[5]Reduction of English Function Words in Switchboard
[6]From Reduction to Emancipation: Is \u201cgonna\u201d A Word?\u2b50
P.133
Corpus Perspectives on Patterns of Lexis
[7]Communicative efficiency and the Principle of No Synonymy: predictability effects and the variation of want to and wanna
Variables:
[8]Some Informal Contractions in American English
\u5199\u5f97\u4e0d\u662f\u5f88\u597d
[9]Exploring the Role of Grammar and Word Choice in Bias Toward African American English (AAE) in Hate Speech Classification, Diyi Yang
In this section, a corpus analysis is carried out to confirm the theories in the literature.
\u600e\u4e48\u542c\uff1a\u7528\u7b2c\u4e09\u4e2ainternational dialect\u8fd9\u4e2a\u5e93\u3002\u91cc\u9762\u53ef\u4ee5\u9009\u62e9African, North American, South American\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u53c8\u6709\u5730\u57df\u4e4b\u5206\u3002\u91cc\u9762\u90fd\u6709transcription\uff0c\u76f4\u63a5\u641c\u7d22\u6709\u6ca1\u6709\u8fd9\u4e09\u4e2a\u8bcd\u7ec4\uff0c\u6709\u5c31\u5b9a\u4f4d\u542c\u4e00\u4e0b\u3002
\u53ef\u80fd\u4e0d\u80fd\u627e\u9f50\u6240\u6709\u53d8\u91cf\uff0c\u6211\u81ea\u5df1\u542c\u7684\u65f6\u5019\u89c9\u5f97\u662f\u5f88\u5c11\u7684\uff0c\u80fd\u627e\u5230\u591a\u5c11\u7b97\u591a\u5c11\u597d\u4e86\u3002
"},{"location":"Ling/Phonetics/reduction/#relevant-corpus-resources","title":"Relevant Corpus Resources","text":"Common Voice
Iterating Dataset Access on Common Voice
People\u2019s Speech\u2b50
MLCommons/peoples_speech \u00b7 Datasets at Hugging Face
International Dialects\u2b50
Accents and Dialects of England | IDEA: International Dialects of English Archive
(a dataset in Kaggle)
openSLR
openslr.org
Stanford CS22S
CS224S: Spoken Language Processing
\u6bcf\u4e2a\u8bb0\u5f55\u4e00\u4e2a\u6bd4\u503c\uff1a#reduction/#\u542c\u4e86\u7684\u53e5\u5b50\u3002\u6bcf\u4e2a\u53d8\u91cf10\uff5e15\u6761\u5373\u53ef\uff0c\u8fd93\u4e2a\u77ed\u8bed\u51fa\u73b0\u4e00\u6b21\u7b97\u4e00\u6761\uff0c\u4e0d\u662f\u4e00\u4eba\u7b97\u4e00\u6761
General Pattern\u2b50
\u53bb\u542c\u4e94\u79cd\u60c5\u51b5
African\u7684\u5728\u5e93\u91cc\u6bd4\u8f83\u5c11
\u5206\u6210\u7537\u5973\u53bb\u542c\uff0c\u671f\u671b#reduction in \u7537>\u5973
\u5f53\u58f0\u5e26\u5904\u4e8e\u6536\u7d27\u72b6\u6001\uff0c\u6d41\u7ecf\u7684\u6c14\u6d41\u4f7f\u58f0\u5e26\u632f\u52a8\uff0c\u8fd9\u65f6\u4ea7\u751f\u7684\u97f3\u662f\u6d4a\u97f3\uff08voiced sound\uff09\uff1b\u5f53\u58f0\u5e26\u5904\u4e8e\u653e\u677e\u72b6\u6001\uff0c\u4e0d\u4f34\u6709\u58f0\u5e26\u632f\u52a8\u7684\u97f3\uff0c\u79f0\u4e3a\u6e05\u97f3\uff08unvoiced sound\uff09\u3002
"},{"location":"Ling/Phonetics/signal/#_2","title":"\u6fc0\u52b1\u6e90\u4e0e\u6ee4\u6ce2\u5668","text":"\u6c14\u6d41\u4e0e\u58f0\u95e8\u662f\u6fc0\u52b1\u6e90\uff0c\u58f0\u9053\u662f\u6ee4\u6ce2\u5668\u3002
"},{"location":"Ling/Phonetics/signal/#_3","title":"\u5171\u632f\u5cf0","text":"\u58f0\u95e8\u7684\u8d28\u91cf\u51b3\u5b9a\u57fa\u97f3\u9891\u7387\uff0c\u57fa\u9891\u7684\u9ad8\u4f4e\u4e5f\u4e0e\u6027\u522b\u548c\u5e74\u9f84\u76f8\u5173\u3002\u7537\u6027\u5927\u7ea6\u572860\uff5e200hz\u3002\u5973\u6027\u548c\u513f\u7ae5\u5927\u7ea6\u5728200\uff5e450hz\u3002
\u4eba\u7684\u53d1\u58f0\u5668\u5b98\uff08\u58f0\u9053\u548c\u53e3\u8154\uff09\u808c\u8089\u8f83\u8f6f\uff0c\u963b\u5c3c\u8f83\u5927\uff0c\u4f1a\u5bf9\u8f83\u591a\u7684\u9891\u7387\u4ea7\u751f\u5171\u9e23\u3002\u628a\u58f0\u9053\u5f53\u4f5c\u4e00\u4e2a\u53d1\u97f3\u7684\u8c10\u632f\u8154\u4f53\u6765\u770b\uff0c\u5f53\u53d1\u97f3\u7684\u6fc0\u52b1\u9891\u7387\u7b49\u4e8e\u58f0\u9053\u7684\u8c10\u632f\u9891\u7387\u65f6\uff0c\u5373\u4e24\u4e2a\u9891\u7387\u76f8\u7b49\uff0c\u58f0\u9053\u5c31\u4f1a\u4ee5\u6700\u5927\u7684\u632f\u5e45\u6765\u56de\u9707\u8361\uff0c\u4e5f\u5c31\u662f\u5171\u9e23\u3002\u5171\u9e23\u5f15\u8d77\u4e86\u8c10\u632f\u8154\u632f\u52a8\uff0c\u63a5\u7740\u58f0\u9053\u5c31\u653e\u5927\u4e86\u67d0\u4e9b\u9891\u7387\u6210\u5206\uff0c\u5e76\u8870\u51cf\u5176\u5b83\u9891\u7387\u6210\u5206\uff0c\u4ece\u800c\u4ea7\u751f\u67d0\u4e9b\u8c10\u632f\u9891\u7387\uff0c\u5728\u9891\u7387\u7279\u6027\u4e0a\u88ab\u653e\u5927\u7684\u8c10\u632f\u9891\u7387\u5c31\u4f1a\u9646\u7eed\u5cf0\u8d77\uff0c\u4e00\u822c\u628a\u8fd9\u4e9b\u5171\u632f\u9891\u7387\u79f0\u4e3a\u5171\u632f\u9891\u7387\uff0c\u5cf0\u79f0\u4e3aformant\u3002
\u5173\u4e8e\u5171\u632f\u9891\u7387\u7684\u5927\u5c0f\uff0c\u56e0\u4e3a\u53e3\u8154\u548c\u58f0\u9053\u53ef\u4ee5\u7ec4\u5408\u6210\u5404\u79cd\u5f62\u72b6\u548c\u5c3a\u5bf8\uff0c\u6240\u4ee5\u58f0\u9053\u6709\u4e0d\u540c\u7684\u5171\u632f\u9891\u7387\u3002
\u5173\u4e8e\u5171\u632f\u9891\u7387\u7684\u8bed\u4e49\uff0c\u7531\u4e8e\u6d4a\u97f3\u548c\u5143\u97f3\u662f\u58f0\u5e26\u632f\u52a8\u4ea7\u751f\u7684\uff0c\u6240\u4ee5\u4e00\u822c\u8ba4\u4e3a\u5171\u632f\u5cf0\u4e0e\u6d4a\u97f3\u548c\u5143\u97f3\u5bc6\u5207\u76f8\u5173\u3002
\u7406\u60f3\u58f0\u9053\u6a21\u578b
\u4e0b\u9762\u56fe\u662f\u4e3b\u8981\u5143\u97f3\u548c\u7b2c\u4e00\u4e8c\u5171\u632f\u5cf0\u7684\u9891\u7387\u5bf9\u5e94\u56fe\u3002
\u4e09\u4e2a\u5143\u97f3\u548c\u5171\u632f\u5cf0\u7684\u5bf9\u5e94\u5173\u7cfb\u5982\u4e0b\u3002\u4e00\u4e2a\u97f3\u7d20\u53ef\u4ee5\u7528\u4e09\u4e2a\u5171\u632f\u5cf0\u8868\u793a\uff0c\u6bcf\u4e2a\u5171\u632f\u5cf0\u7684\u9891\u8c31\u7279\u6027\u90fd\u53ef\u4ee5\u7528\u4e00\u4e2aGMM\u6765\u5efa\u6a21\u62df\u5408\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e09\u4e2aGMM\u53ef\u4ee5\u5efa\u6a21\u62df\u5408\u4e00\u4e2a\u97f3\u7d20\uff0c\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48HMM\u9700\u8981\u4e09\u4e2a\u72b6\u6001\u3002\u800c\u4e00\u822c\u5b9e\u9645\u4e2d\u6211\u4eec\u7528\u4e94\u4e2aHMM\u72b6\u6001\uff0c\u56e0\u4e3a\u6e05\u97f3\uff08\u975e\u6587\u672c\u56e0\u7d20\uff09\u6bd4\u8f83\u590d\u6742\uff0c\u9700\u8981\u4e94\u4e2a\u5171\u632f\u5cf0\u624d\u80fd\u8f83\u597d\u8868\u793a\u3002
\u4e8b\u5b9e\u4e2d\u7684\u95ee\u9898\u6ca1\u6709\u8fd9\u4e48\u7b80\u5355\uff0c\u5982\u679c\u8003\u8651\u53d8\u65f6\uff0c\u5f53\u5f62\u6210\u4e00\u4e2a\u8bcd\u8bed\u65f6\uff0c\u6bcf\u4e2a\u97f3\u7d20\u603b\u4f1a\u4e0e\u524d\u540e\u7684\u97f3\u7d20\u5173\u8054\uff0c\u79f0\u4e3a\u534f\u540c\u53d1\u97f3\u3002\u7531\u4e8e\u534f\u540c\u53d1\u97f3\u7684\u4f5c\u7528\uff0c\u524d\u540e\u4e24\u4e2a\u5171\u632f\u5cf0\u53ef\u80fd\u4f1a\u91cd\u53e0\u6216\u8005\u9760\u8fd1\uff0c\u6216\u8005\u76f8\u4e92\u4f5c\u7528\uff0c\u6b64\u65f6\u5f88\u96be\u8bf4\u4e09\u4e2a\u5171\u632f\u5cf0\u8868\u793a\u4e00\u4e2a\u72ec\u7acb\u7684\u5143\u97f3\uff0c\u8fd9\u4e09\u4e2a\u5171\u632f\u5cf0\u53ef\u80fd\u4f1a\u5e26\u6709\u522b\u7684\u524d\u540e\u97f3\u7d20\u9891\u8c31\u7279\u6027\u5728\u5176\u4e2d\u3002
"},{"location":"Ling/Phonetics/signal/#spectrogram-spectral-waterfall-voice-print","title":"\u8bed\u8c31\u56fe(spectrogram, spectral waterfall, voice-print)","text":"\u8bed\u8c31\u56fe\u6709\u4e09\u4e2a\u7ef4\u5ea6\uff1ax\u8f74\u65f6\u95f4\uff0cy\u8f74\u9891\u7387\uff0cz\u8f74\u8f90\u503c\u3002
"},{"location":"Ling/Phonetics/signal/#_4","title":"\u5143\u97f3\u548c\u8f85\u97f3\u7684\u8bed/\u9891\u8c31\u56fe\u7279\u5f81","text":"\u5143\u97f3\u7684\u8bed\u8c31\u56fe\u5dee\u5f02
f3\u6700\u660e\u663e\u7684\u4f53\u73b0\u662f\u5728\u8f85\u97f3/r/\u4e2d\uff0cf3\u660e\u663e\u4f4e
\u8f85\u97f3\u7684\u8bed\u8c31\u56fe\u5dee\u5f02 \u533a\u5206voiced\u548cvoiceless
four acoustic properties of plosives
\u7b2c\u56db\u7ae0\u5143\u8f85\u97f3\u7684\u58f0\u5b66\u77e5\u8bc6\u8fa8\u6790.ppt
Music lab https://esp.mit.edu/download/a29f71f1fddf4f6470eb50726aa98de4/L7357_Phonetics_2hrs_Splash2013.pdf
https://www.mq.edu.au/__data/assets/pdf_file/0009/911646/vowels.pdf
Acoustic structure of consonants
Human Voices and the Wah Pedal
3.2. Acoustic Aspects of Consonants
"},{"location":"Ling/Phonetics/signal/#_5","title":"\u5e38\u7528\u97f3\u9891\u7279\u5f81","text":"\u97f3\u9891\u7279\u5f81\u63d0\u53d6\u2014\u2014\u5e38\u7528\u97f3\u9891\u7279\u5f81 - LeeLIn\u3002 - \u535a\u5ba2\u56ed
\u5f00\u6e90\u9879\u76eeaudioFlux: \u9488\u5bf9\u97f3\u9891\u9886\u57df\u7684\u6df1\u5ea6\u5b66\u4e60\u5de5\u5177\u5e93 - audioFluxLab - \u535a\u5ba2\u56ed
"},{"location":"Ling/Pragmatics/ca_da/","title":"Research Methods: Conversation Analysis and Discourse Analysis","text":""},{"location":"Ling/Pragmatics/ca_da/#discourse-analysis","title":"Discourse Analysis","text":"Some discourse analysis are taught in linguistic departments (Johnstone, 2018)
Foucault (1972, 1980) use 'discourse' to refer to the ways of talking and thinking constitute ideologies (set of interrelated ideas) and serve to circulate power in society, and in the sense involved patterns of belief and habitual actions as well as patterns of language.
Johnstone, Barbara. 2018. Discourse Analysis (3rd ed.). UK: Wiley-Blackwell.
"},{"location":"Ling/Pragmatics/ca_da/#conversational-analysis","title":"Conversational Analysis","text":""},{"location":"Ling/Semantics/","title":"Index","text":""},{"location":"Ling/Semantics/#contents","title":"Contents","text":"1 - Definition Clearification
This chapter provides a brief introduction to the terminologies involved in semantics.\n
2 - Logics & Formal Semantics
This chapter first introduces the semiotics in formal semantics (which adopts a similar system with that in the logics). It then discusses about the semantics in two perspectives: the propositional logic and the predicate logic. It also introduces several basic rules in logic inference.\n
3 - Scope Ambiguity
This chapter discusses on the unsolved questions in scope ambiguity.\n
"},{"location":"Ling/Semantics/#grading","title":"Grading","text":"mid-term: 35%
final: 50%
participation: 15%
"},{"location":"Ling/Semantics/#two-tests","title":"Two tests","text":"Two tests will be given during the term, one in the middle and one at the end of the term, covering all the material covered up to that point in the course. The tests will be a combination of various types of questions, including true/false and short essay.
"},{"location":"Ling/Semantics/#final-review-for-fun","title":"Final Review & For Fun","text":"The following parts are written in preparation for the final review but I upload it as well for you to read for fun.
"},{"location":"Ling/Semantics/#noble-semanticians","title":"Noble Semanticians","text":"Name Field Contribution Live Nation Institution Fun facts Noam Chomsky mainly in syntax generative grammar, transformational grammar, government and binding theory, minimalist program, productivity of language, recursivity of language 1928- USA MIT Most prominent linguist alive Ferdinand de Saussure linguist and semiotician founder of semiotics. concepts: sign, signifier vs. signified, diachronic vs. synchronic, language vs. parole, paradigmatic vs. syntagmatic 1857-1913 Switzerland University of Geneva, Switzerland Charles Sanders Peirce philosopher, mathematician, logician founder of semiotics. concepts: index, icon, symbol. 1839-1914 Milford Pennsylvania JHU Michel Br\u00e9al comparative grammar coined the term \u201csemantics\u201d, diachronic focus 1832-1915 born in Rheinlan (Germany), studied in Paris and Berlin in Paris Leonard Bloomfield structural linguistics structural linguistics, language as a self-regulating system, behaviorism(stimulus-response testing) 1887-1949 Yale University reject introspection Aristotle polymath term logic, initiator of western scientific tradition 384-322 BC Stagira, Greece tutor of Alexander the Great Gottlob Freg philosopher, logician, mathematician predicate logic, sense(sentence\u2019s proposition) vs. reference (its truth value) 1848-1925 German University of Jena extreme right-wing views Peter Geach philosopher, professor of logic donkey sentence (1962) 1916-2013 England Oxford Richard Montegue semanticist Montegue grammar: syntax and semantics go together 1930-1971 student of Alfred Tarski, gay man, killed in his apartment, four influential papers Gareth Evans philosopher philosophy of mind, work on reference, e-type anaphora 1946-1980 England Oxford Irene Heim semanticist definite and indefinite pronouns 1954- German, Munich MIT, phd 1982 advisor: Barbara Partee Hans Kamp philosopher and linguist discourse representation theory (DRT) 1954- Dutch Bertrand Russell philosopher, logician logic, philosophy of mathematician 1872-1970 Wales, Britain Cambridge Henri\u00ebtte de Swart linguist tense and aspect, negation, bare nominals and indefinite noun phrases. She has also investigated the role of semantics in language evolution, and was involved in the development of bidirectional optimality theory. 1961- Dutch director of Netherlands Graduate School of Linguistics and Utrecht Institute of Linguistics"},{"location":"Ling/Semantics/#example-questions","title":"Example questions","text":"What is a donkey pronoun?
A donkey sentence is such that an expected existential is interpreted as universal taking wide scope.\n
What is a discourse pronoun:
outside the scope of existing quantifier\ne.g. No student studies semantics. He is outside.\n
The scope of a quantifier is always bound in the clause it appears.
True\n
What is quantifier raising?
Chmosky and May.\nLF, \n
What are De Morgan\u2019s laws?
~(p or q) <=> (~p) and (~q)\n~(p and q) <=> (~p) or (~q)\n
What are conditional laws
p -> q <=> ~p or q\n
When is the indefinite \u201ca\u201d not an existential quantifier?
1. donkey sentence\n2. generic noun phrase. A woman is difficult to please. \\forall x(Wx -> Dx)\n3. John is a plumber.pj\n
2 readings: Some boy smiled at Jane and some boy kissed Molly.
\\exist x(Bx and Sx,j and Kx,m)\n\\exist x(Bx and Sx,j) and \\forall y(By and Ky,m)\n
2 Types of Recursion
embedding and coordination\n
"},{"location":"Ling/Semantics/ambiguity/","title":"Scope Ambiguity","text":""},{"location":"Ling/Semantics/ambiguity/#scope-ambiguity","title":"Scope Ambiguity","text":""},{"location":"Ling/Semantics/ambiguity/#scope-and-anaphora","title":"Scope and Anaphora","text":"antecedent vs. postcedent
anaphor vs. cataphor
Predicate logic is suited to capture natural language meaning
allow recursion = recursivity
two sources of recursion
some boy kissed every girl.\n\nEvery girl was kissed by some boy.\n
Someone mentioned tehy called everyone.\n\n\\forall x: Px\\forall y(M(x, Cxy))\n
linear order: negative polarity item
graph TD\n DS -.Transformation.-> SS\n SS -.send off.-> PF\n SS -.send off.-> LF\n PF -.acoustic representation.-> SS\n LF -.semantic interpretation.-> SS\n
Transformation:
CALLOUT: annotation, connotation and denotation
annotation
connotation: intension.
A meaning of a word or phrase that is suggested or implied, as opposed to a denotation, or literal meaning. A characteristic of words or phrases, or of the contexts that words and phrases are used in.
The\u00a0connotations\u00a0of the phrase \"you are a dog\" are that you are physically unattractive or morally reprehensible, not that you are a canine.
A technical term in logic used by J. S. Mill and later logicians to refer to the attribute or aggregate of attributes connoted by a term, and contrasted with\u00a0denotation\u00a0.
The two expressions \"the morning star\" and \"the evening star\" have different\u00a0connotations\u00a0but the same denotation (i.e. the planet Venus).
denotation
Quantifier-raising - NC RM - syntactic structure comes before the semantic structure - The movement we make in SS to remove ambiguity in DS is called quantifier-raising. - take the quantifier to the higher position to show the scope
Quantifier-in - Montague grammar - The derivational illustration is called quantifier-in. - each predicate take an argument once a time
Quantifier storage - Cooper storage - semantic ambiguity not represented in syntactic structure - semantic representation in which scope ambiguities are obtained without special syntactic rules
"},{"location":"Ling/Semantics/ambiguity/#quantifier-in","title":"Quantifier-in","text":"interrogative: asking a question
which woman does every man love?\n
which scopes over every.
"},{"location":"Ling/Semantics/ambiguity/#scope-ambiguity_1","title":"Scope ambiguity","text":"e.g. some boy did not laugh.
\\exist x (Boy(x) and ~Laugh(x))\n~\\exist x (Boy(x) and Laugh(x))\n
some boy kissed no girl.
\\exist x (Boy(x) and ~\\exist y (Girl(y) and Kiss(x, y)))\n~\\exist y (Girl(y) and \\exist x (Boy(x) and Kiss(x, y))): there was no girl kissed by a boy\n
every boy kissed no girl.
\\forall x (Boy(x) and ~\\forall y(Girl(y) and Kiss(x, y)))\n
"},{"location":"Ling/Semantics/ambiguity/#deictic","title":"Deictic","text":"No boy said he was hungry.
No boy was present. He was outside instead.: \u201che\u201d is trying to refer to \u201dno boy\u201d but outside the scope.
pronoun \\(\\sub\\) anaphora
"},{"location":"Ling/Semantics/ambiguity/#discourse-anaphora","title":"Discourse Anaphora","text":"e.g.
Every student was present and she was interested.\n
every: scopes over \u201cEvery student was present\u201d
every: an indefinite quantifier. \u201cshe\u201d\u2019s antecedent is not clear
\u201cshe\u201d is hardly bound by the antecedent. \u201cshe\u201d is free * ungrammatical: \u4e0d\u5408\u8bed\u6cd5\u7684, syntactic
"},{"location":"Ling/Semantics/ambiguity/#infelicitous-semantic-fit-the-context","title":"infelicitous: \u4e0d\u5408\u9002\u7684, semantic, fit the context","text":"discourse pronoun: in separate clauses
sentence quantifier:
Some boy said he was hungry.\nNo boy said he was hungry.\n
discourse quantifier:
Some boy was present; he was hungry.\n#No boy was present; he was hungry. // he is free\n
coreference individual constants
Fred thought he was the the best\n
binding individual variables
Every student thinks he/she is the best\n
So we may conclude the following rules for e-type anaphora. BUT this part has NOT been verified with any authority. Do NOT take them as given truths during exams.
e.g. No boy thinks that he has a chance.
~\\exist x(Boy(x) and Think(x, Has-a-chance(x)))\n
A particular boy said he wanted to kiss every girl. He then did it.
\\exist !x(Bx and W(x, K(x, \\forall y(Gy -> K(x, y))))) and K(x, y)\n
"},{"location":"Ling/Semantics/ambiguity/#donkey-anaphora","title":"Donkey anaphora","text":"if a farmer owns a donkey, he beats it.
* \\exist x (Fx and \\exist y (Dy and O(x, y))) -> B(x, y)\n\\forall x \\forall y (Fx and Dy and O(x, y) -> B(x, y))\n
= every farmer who owns a donkey beats it.
\\exist x(Fx and \\exist y (Dy and O(x, y)) -> B(x, y)) // y is free\n
\u2757\u2757\u2757
A donkey sentence is such that an expected existential is interpreted as universal taking wide scope.
donkey pronoun can be: it, him, they (can also be plural forms)
\u201ca\u201d: generic indefinite
A woman is a difficult thing to please.\n
[Every farmer [who owns a donkey] beats it.]
universal wide scope: it scopes more over the relative clause
The problem - Existential with narrow scope - interpreted as universal with wide scope - in conditional clauses - in restriction of every
Conclusion - the machinery of predicate logic is broken - cannot capture meaning of natural language
If a student tries, she passes the exam.
(\\exist x(Sx and Tx)) -> Py ; y is free\n\\exist x((Sx and Tx)) -> Py)\n
interpretation
\\forall x((Sx and Tx) -> px)\n
Solutions for donkey anaphora:
E-type anaphora
initial examples
A student came in. She had a question about the exam.\nshe = the student came in\n\nBill owns some sheep and Max vaccinates them.\nthem = the sheep Bill owns. E-type pronoun, some sheep scopes over the first half\n
If a student likes Copenhagen, she is happy.
she = for every case we examine, the student is \n
every student who reads a semantic paper likes it.
Bill owns a cat. Max takes care of it.\nBill is a cat-owner. #Max takes care of it.\n
DRT (Dynamic binding theory)
Unselective binding example of the subject is \u2018unselectively bound\u2019 by a special \u2018generic operator.
Dogs bark.\nA dog barks.\n
Reference: Unselective Binding
"},{"location":"Ling/Semantics/ambiguity/#chapter-6-in-short-discoursedonkey-anaphora","title":"Chapter 6 in short: Discourse/Donkey Anaphora","text":"(\u52a0\u7c97\u7684\u662fDonkey anaphora\u548cE-type anaphora\u7684\u533a\u522b)
Discourse: basic unit of interpretation
Donkey sentence: is such that an expected existential is interpreted as universal taking wide scope. / sentences that contain a pronoun with clear meaning but whose syntactical role in the sentence poses challenges to grammarians (wikipedia)
e.g.
every farmer who owns a donkey beats *it*.\nit: (corresponding to the) existential (\"a\") but interpreted as universal\n
every police officer who arrested a murder insulted *him*.\nhim\n
every farmer who owns some sheep cleans *them*.\nthem\n
donkey anaphora = donkey pronoun: it, him, they (can also be plural forms)
Analysis of donkey anaphora: Montague grammar
e.g.
\\forall x(Farmer(x) and \\exist y (Donkey(y) and Owns(x,y)) -> Beat(x,y))\n
Anaphoric relations in sentence and discourse - E-type anaphora: pronoun outside the scope of binder, not bound, content of pronoun reconstructed, reconstruction based on context - in separate sentences
```\n A student came in. *She*(the student came in) had a question about the exam.\n ```\n\n- in the same sentence but outside the scope\n ```\n If a student likes Copenhagen, *she*(for every case we examine, the student in question who likes Copenhagen) is happy.\n ```\n\n- problem of compound: antecedent must appear as a noun?\n ```\n Bill owns a cat. Max takes care of it.\n Bill is a cat-owner. # Max takes care of it.\n ```\n
Anaphora resolution - TODO
"},{"location":"Ling/Semantics/definitions/","title":"Definition Clarification","text":""},{"location":"Ling/Semantics/definitions/#what-is-semantics","title":"What is semantics?","text":"parenthesis
small dogs and cats: \n- small (dogs and cats)\n- (small dogs) and cats\n\n// example of scope of quantifier\n
logical quantifier
every body did not cry:\n- every not (boy did cry) 'no boy did cry'\n- not every (boy did cry) 'at least one boy did cry'\n
everything but the subject e.g. John likes grammar.
content verb or adjective taking arguments e.g. like (John, grammar).
graph TD\n Language_Ability --> Competence\n Language_Ability --> Performance\n Competence --> Grammar\n Competence --> Lexicon\n Grammar --> Semantics\n Grammar --> Phonology\n Grammar --> Syntax\n Grammar --> Pragmantics\n
"},{"location":"Ling/Semantics/definitions/#semantics-syntax","title":"Semantics & Syntax","text":""},{"location":"Ling/Semantics/definitions/#syntax-needs-semantics","title":"Syntax needs semantics","text":"We can/cannot study syntax without semantics.
Colorless green ideas sleep furiously.\n
Deixis is how objects, events and situations relate to the here and now of the speakers. It shows that utterance meaning cannot be fully determined by sentence meaning.
(Last week) (I) play(ed) tennis with Chris.\n
"},{"location":"Ling/Semantics/definitions/#deictic-vs-anaphoric-use-of-pronouns","title":"Deictic vs. Anaphoric use of pronouns","text":"Deictic: pointing context Anaphoric: linguistic expression context. pronoun resolution: antecedent - pronoun
\ud83d\udcad index - indices (higher register) / indexes \ud83d\udcad Desiderata (high-register way to say Goal, desideratum. sl.)"},{"location":"Ling/Semantics/definitions/#map-of-semantics-taxomony","title":"Map of Semantics / Taxomony","text":"Semantics - lexical semantics - meaning of lexical items - smaller unites - mainly words - morphemes - compositional semantics - meaning of larger units - phrases and sentences - word combination
"},{"location":"Ling/Semantics/definitions/#utterance-sentence-proposition","title":"Utterance / Sentence / Proposition","text":"abiguity: bank, punch, pitcher\nsynonymy: beautiful-lovely, antonymy: male-female\nhyponymy: set -> superset\ntaxonomy: set -> subset\nsymmetric relation: marry. mutually entail each other\nconverse relation: send, sell\nmeronomy:
"},{"location":"Ling/Semantics/definitions/#1-homonymy","title":"1) homonymy","text":"part-whole relationship
subtypes of meronymy
pistachio - almond taxonymy\nlaugh - cry move in - move out\ncry - weep\nRMB - monetary unit\ngrilfriend - wife\nsit - stand\njump - hop\ngood - bad\nbeat - beet\nrise - fall reverse\ncigarette - cigar taxonymy\nkid - goat dragon - monster\n
"},{"location":"Ling/Semantics/definitions/#compositional-semantics","title":"Compositional semantics","text":"Michel Br\u00e9al: coined semantics
Ferdinand de Saussure: semiotician, diachronic vs. synchronic.
Leonard Bloomfield: structural linguistics, Language, behaviorism(stimulus-response testing). reject introspection(theorize about language learning by thinking about on ones own experience)
"},{"location":"Ling/Semantics/definitions/#diachronic-synchronic","title":"Diachronic & Synchronic","text":"Noam Chomsky Syntax
"},{"location":"Ling/Semantics/definitions/#generative-grammar","title":"Generative Grammar","text":"e.g. Flying planes can be dangerous.
graph TD\n are --> planes\n planes --> flying\n are --> dangerous\n
graph TD\n is --> flying\n flying --> planes\n is --> dangerous\n
"},{"location":"Ling/Semantics/definitions/#pronoun-resolution","title":"pronoun resolution","text":"anaphora
John said he would helps.\nNo boy said he would help. no boy: all the boy not, not exist a boy\n
coreference(coreferential): refer to same person
notes: cf. compare, e.g. for example
graph TD\n Inference --> Entailment\n Inference --> Presuppositions\n Inference --> Implicature\n
any conclusion drawn from a set of propositions, from something someone has said and so on.
"},{"location":"Ling/Semantics/definitions/#entailment","title":"Entailment","text":"Three girls were present. -> More than two girls were present.\nThree girls were not present. kills More than two girls were present.\n
Cannot be cancelled
# Three girls were present, but actually two girls come.\n#: semantically wrong\n
"},{"location":"Ling/Semantics/definitions/#presupposition","title":"Presupposition","text":"Jim regrets ignoring the first problem. -> Jim has the first problem.\nJim does not regret ignoring the first problem. -> Jim has the first problem.\n
cannot be cancelled
# Jim regrets ignoring the first problem, but he does not have the first problem.\n
"},{"location":"Ling/Semantics/definitions/#implicature","title":"Implicature","text":"Susan blushes when Jim looks at her, but she does not have a crush on him.\n
"},{"location":"Ling/Semantics/definitions/#compositionality","title":"Compositionality","text":"Proposed by Noam Chomsky, the term compositionality entails three dimension.
The meaning of the whole is a function of the meaning of its parts and the way they are put together.: \u2026 is determined by\u2026
"},{"location":"Ling/Semantics/formal_semantics/","title":"Logics & Formal Semantics","text":""},{"location":"Ling/Semantics/formal_semantics/#metalanguage","title":"Metalanguage","text":"a. January has 31 days.\nb. *******January******* has 7 letters.\nb*. 'January' has 7 letters.\n
Liar sentence
(31) Sentence (31) is false.\n
solutions: (\u4e0d\u8003)
fuzzy logic
x = NOT(x)\nx = 1 - x\nx = 0.5\n
Alfred Tarski paradox arises only in languages that are \u201csemantically closed\u201d.
Arthur Prior equivalent
This statement is false.\nThis statement is true and this statement is false.\n
Saul Kripke Whether a sentence is paradoxical or not can be depend upon contingent facts.
A majority of what Jones says about me is false.\n
Smith is a big spender.\nSmith is soft on crime.\nEverything Smith says about me is true.\n
If a statement's truth value is ultimately tied up in some evaluable fact about the world, that statement is \"grounded\". If not, that statement is \"ungrounded\". Ungrounded statements do not have a truth value. Liar statements and liar-like statements are ungrounded, and therefore have no truth value.
Jon Barwise and John Etchemendy \u201cdenial\u201d or \u201cnegation\u201d
Dialetheism
Dialetheism is the view that there are true contradictions. Dialetheism raises its own problems. Chief among these is that since dialetheism recognizes the liar paradox, an intrinsic contradiction, as being true, it must discard the long-recognized\u00a0principle of explosion, which asserts that any proposition can be deduced from a contradiction, unless the dialetheist is willing to accept trivialism \u2013 the view that\u00a0all propositions are true. Since trivialism is an intuitively false view, dialetheists nearly always reject the explosion principle. Logics that reject it are called\u00a0paraconsistent.
Non-cognitivism
logic overview
graph TD\n Logic --> Logic_from_antiquity\n Logic --> Predicate_Logic\n Logic_from_antiquity --> Term_Logic\n Logic_from_antiquity --> Propositional_Logic\n
logic from antiquity: older
predicate logic: newer
Aristotle: term logic
Gottlob Frege: predicate logic
"},{"location":"Ling/Semantics/formal_semantics/#history-of-logics","title":"History of Logics","text":"Not applied for - question (?) - exclamation - modal: modal logic
\ud83d\udcad ergo: therefore"},{"location":"Ling/Semantics/formal_semantics/#term-logic","title":"Term logic","text":""},{"location":"Ling/Semantics/formal_semantics/#modus-ponens","title":"Modus Ponens","text":"Means of putting, MP syllogism, affirming the antecedent
P(conditional statement): If it rain, I do not go to school.\nH: It rains.\nC: I do not go to class.\n
Formal fallacy: affirming the consequent. Abductive reasoning.
P: If it rains, I will not go to class.\nH: I do not go to class.\nC: * It rains.\n
"},{"location":"Ling/Semantics/formal_semantics/#modus-tollens","title":"Modus Tollens","text":"Means of carrying, MT syllogism, denying the consequent.
P: If it has not been cloudy, it does not rain.\nH: It rains.\nC: It has been cloudy.\n
"},{"location":"Ling/Semantics/formal_semantics/#hypothetical-syllogism","title":"Hypothetical syllogism","text":"principle of transitivity
P: If it rains, the soils goes wet. If the soil goes wet, the plants grow.\nH: It rains.\nC: The plants grow.\n
"},{"location":"Ling/Semantics/formal_semantics/#disjunctive-syllogism","title":"Disjunctive syllogism","text":"two premises and a conclusion
P: It either rains or its sunny.\nH: It rains.\nC: It is not sunny.\n
"},{"location":"Ling/Semantics/formal_semantics/#three-types-of-reasoning","title":"Three types of reasoning","text":"Deductive reasoning
general to the particular. based on entailment
Inductive reasoning
particular to the general. empiricism
Abductive reasoning
formal fallacy. All dogs bark, Fido barks, Fido is a dog.
Abductive reasoning allows inferring a as an explanation of b. As a result of this inference, abduction allows the precondition a to be abducted from the consequence b.
Properly used, abductive reasoning can be a useful source of\u00a0priors in\u00a0Bayesian statistics.
John is friendly or John is not friendly.\n
p V_e ~p T T F F T T John is friendly and John is not friendly.\n
p and ~p T F F F F T It is not the case that John is not friendly.\n
~ ~ p T F T F T F contingent.
It is not the case that John is hungry or John is not grumpy.\n
~( p or ~q F T T T F T T F F F T T T F F F"},{"location":"Ling/Semantics/formal_semantics/#material-implication","title":"Material implication \u2192","text":"converse: q\u2192p. affirming the consequent
inverse: ~p\u2192~q. denying the antecedent
contrapositive: ~q\u2192~p. modus tollens
given p\u2192q.
Although it was extremely cold, Sally did not stay indoors.
~q->p\np and ~q\n
We get a holiday, or we protest.
~p->q\np or q\n
Jone said that Jane helped him.
p\np and q\n
John\u2019s sister burped
p: John has a sister. presupposition, assume it true\nq: This sister burped.\np\np and q\n
John arrives before Jane left
p before q\n
John did not arrive before Jane left.
~p before q\np ~before q\n
"},{"location":"Ling/Semantics/formal_semantics/#predication-and-quantification","title":"Predication and Quantification","text":"universal quantifier: every, each, all, any, only
existential quantifier: a, some, there is \\(\\exist\\), for all \\(\\forall\\)
predicate, argument
John may like Sally.
predicate: may like\n
John has a crush on Sally.
predicate: has a crush on\n
Frank is the father of Susan.
predicate: is the father of\n
Frank is Susan\u2019s father.
predicate: is...'s father\n
Adjunct: if, probably, means, of course, early
Valent, empty place holder: formal subject
"},{"location":"Ling/Semantics/formal_semantics/#collective-and-distributive-readings","title":"Collective and distributive readings","text":"Jogn and Molly ate a pizza.\np: one pizza, ate one together. distributive\np and q: two pizzas, each ate a pizza. collective\n
Cinthia and Sam have saved 100 dollars.\np: together 100 dollars\np and q: 200 dollars\n
Content verb is a predicate, but functional verbs are not
John obviously spoke with Jane because he had to.
predicate: spoke with\nargument: John, Jane\nadjuncts: obviously, because he had to.\n
If I get a chance, I will probably try to avoid the mistake.
predicate: will try to \nargument: I, avoid the mistake\nadjuncts: If I get a chance, probably\n
John performed Jill\u2019s operation first.
\n
The person who talk loudly is Jim\u2019s father.
predicate: is someone's father\nargument: the person who talk loudly, Jim\nadjunct: \n
the talking loudly person
predicate: talking\nargument: person\nadjunct: loudly\n
predicate: the nodes that are connected in SUD parsing tree
universal dependency (UD)
syntactic-universal dependency (SUD)
graph TD\n Primitive_units_within_propositions --> Predicates\n Primitive_units_within_propositions --> Arguments\n Arguments --> individuals_Terms\n individuals_Terms --> constants\n individuals_Terms --> variables\n
lexical predicates vs. syntactic predicates
individual constants vs. individual variables
e.g. We think John likes Susan.
T(w, Lj,s)\n
Types of predicates:
e.g. Monica hid her bicycle.
x hide y: Hx,y\nMonica: m\nher bicycle: b\nHm,b\n
e.g. Monica did not hide her bicycle.
x hide y: Hx,y\nMonica: m\nher bicycle: b\n~Hm,b\n
e.g. Monica laughed and cried.
Monica: m\nlaugh: L()\ncry: C()\nLm and Cm\n
e.g. Jim sent Monica his dog.
Sj,m,d\n
e.g. William did not help or hinder Mike.
~ (H1w,m or H2w,m) \n
e.g. Jennifer promise to help.
P(j, Hj)\n
e.g. Jennifer did not promise to help.
~P(j,Hj)\n
e.g. Jennifer promise to not laugh.
P(j,~Lj)\n
e.g. Mike claimed he wanted to help.
C(m, W(m/x, Hm/x))\n\nm: Mike\nx: maybe some other\n
e.g. John asked Mandy to stop laughing.
A(j, m, S(m, Lm))\n
e.g. John and Larry called Molly.
Cj,m and Cl,m\nC(j and l, m)\n
e.g. Molly did not call John and Larry.
~C(m, j) and ~C(m, l)\n~C(m, j and l)\n~C(m, j) or ~C(m, l)\n
entailment: (universal instantiation)
every dog barks \u2192 if something is a dog, then it is a dog.
Universal quantification
\\(\\forall\\)x (Dx \u2192 Bx)
D = (d1, d2, d3,\u2026)
\\(\\forall\\)x (Dx \u2192 Bx)= (Bd1 and Bd2 and Bd3, \u2026.)
Existential quantification
\\(\\exist\\)x (Dx and Bx)
D = (d1, d2, d3,\u2026)
\\(\\exist\\)x (Dx and Bx) = (Bd1 or Bd2 or Bd3, \u2026.)
e.g. Every cat barfed.
\\forall x (Cx -> Bx)\n
e.g. The cat barfed.
Bc\n
e.g. Bill fed cat.
\\forall x (Cx -> Fb,x)\n
e.g. Some dog barked at Fred.
\\exist x (Dx and Bx,f)\n
e.g. Fred scolded some dog.
\\exist x (Dx and Sf,x)\n
e.g. Fred and Susan avoid some dog.
\\exist x (Dx and Af,x and As,x)\n\\exits x (Dx and Af,x) and \\exist y (Dy and Af,s)\n
e.g. No dog barks.
\\forall x (Dx -> ~Bx)\n~\\exist x (Dx and Bx)\n
e.g. Bill fed no dog.
~\\exist x (Dx and Fb,x)\n\\forall x (Dx -> ~Fb,x)\n
e.g. No dog barked at Susan or chased Fred.
~\\exist x ((Dx and (Bx,s or Cx,f))\n\\forall x ((Dx -> (~Bx,s and ~Cx,f))\n\\forall x ((Dx -> ~(Bx,s or Cx,f))\n
Scope ambiguity
e.g. Some boy kissed every girl.
\\exist x \\forall y (Bx and (Gy -> Kx,y)) = \\exist x(Bx and \\forall y (Gy -> Kx,y))\n\\forall y \\exist x (Gy -> (Bx and Kx,y)) = \\forall y (Gy -> \\exist x (Bx and Kx,y))\n
Every boy kissed some girl.
\\forall x (Bx -> \\exist (Gy and Kxy)) <=> \\forall x \\exist y (Gy and Kxy)\n
Every students did not laugh.
\\forall x (Sx -> ~Lx) <=> ! \\exist x (Sx and Lx)\n~\\forall x (Sx -> Lx) <=> \\exist (Sx and ~Lx)\n
Not every student laughs.
~\\forall x (Sx -> Lx) <=> \\exist (Sx and ~Lx)\n
graph TD\n laughed --> student\n student --> /every\n /every --> not\n
each studnet did not laugh.
\\forall x (Sx -> ~Lx) \n~\\forall x (Sx -> Lx)\n
"},{"location":"Ling/Semantics/formal_semantics/#polarity-item","title":"Polarity item","text":"any: negative polarity item
John did not pass every exam.
~\\forall x (Ex -> Pj,x) <=> \\exist x (Ex and Pj,x)\n\\forall x (Ex -> ~Pj,x)\n
John did not pass any exam.
\\forall x (Ex -> ~Pj,x)\n
e.g.
Jack saw a rat.
\\exist x (Rx and Sj,x) \n
Jack is a rat.
the quantifier is in the predicate but not the argument. here rat is a constant.
Rj\n
Jack knows no genius.
use not exist to render \u201cno\u201d
~\\exist x (Gx and Kj,x) <=> \\forall x (Gx -> ~Kj,x)\n
Jack is no genius. <=> Jack is not a genius.
~Gj\n
These problems are difficult.
Dp\n
These problems are difficult ones.
Dp\n
All the problems are difficult.
\\forall x (Px -> Dx)\n
These problems are all the problems.
Ap\n
These problems are not all the problems.
~Ap\n
Jack is our plumber.
Pj\n
Our plumer is Jack. (has presupposition)
Pj\n
Everything counts.
whether thing includes animate and inanimate.
\\forall x (Cx)\n\\forall x (Tx -> Cx)\n
Everybody counts.
*\\forall x (Cx)\n\\forall x (Px -> Cx)\n
predicates
some prepositions.
The present under the tree is big. (prepositions that gives location)
argument nouns.
common nouns
content verbs are the core of syntactic predicates
adjectives are most always the core of syntactic predicates.
e.g. Mike\u2019s wife thinks Mikes if lazy.
predicates inside individual constants are presuppositional
A thin man was present.
predicates inside \u2026 .are propositional
e.g. Every barking is harmless
has true or false impact on the truth
\\forall x ((Dx and Bx) -> Hx)\n
this proposition has to show up in the predicate
The barking dog is harmless.
Hd\n
the presupposition does not show in the predicate
John avoids every dog he sees.
\\forall x ((Dx and Sj,x) -> Aj,x)\n
John said every dog barks.
intensional
Sj\nS(j,\\forall x (Dx -> Bx)) \nSj,I ; I for intensional argument predicate\n
"},{"location":"Ling/Semantics/formal_semantics/#adjunct-predicates","title":"Adjunct predicates","text":"Jane probably teased Sam last night
John arrived drunk.
Jim burped twice.
twice: propositional or presuppositional
Susan did not cheat yesterday.
Mary stayed because John stayed.
Mary did not stay because John stayed
Every boy was hungry
\\forall x: Bx(Hx)\n
Some boy was hungry.
\\exist x: Bx(Hx)\n
Every cat barfed.
\\forall x: Cx(Bx)\n
Bill fed every cat.
\\forall x (Cx, Fb,x)\n\\forall x: Cx(Fb,x)\n
Some dog barked at Fred.
\\exist x (Dx, Bx,f)\n\\exist x: Dx(Bx,f)\n
Fred and Susan avoid some dog.
\\exist x(Dx and (Af,x and As,x))\n\\exist x: Dx (Af,x and Af,x)\n
No dog barks.
~\\exist x (Dx and Bx) <=> ~\\exist x: Dx (Bx)\n
"},{"location":"Ling/Semantics/formal_semantics/#formal-predicate-semantics","title":"Formal Predicate Semantics","text":"graph TD\n Semantic_Rules --> Model\n Semantic_Rules --> Valuation_Function\n Model --> Universe_of_Discourse\n Model --> Interpretation_Function\n Universe_of_Discourse --> entities\n
interpretation function I
I(name) \u2192 meaning\n
assignment function g[x/e]
g(type of object) -> meaning\n
valuation function V
V(p) = 1/0\nV(Bs) = 1/0\n
[[\\alpha]]^M the denotation of \\alpha wrt M (same as interpretation function I)
[[name]]^M -> meaning\n
\u751f\u6210\u53e5\u6cd5\u548c\u6210\u5206\u53e5\u6cd5\u4e4b\u95f4\u7684\u533a\u522b
[The big book of poems with the blue cover] is on the table.\n
\u6210\u5206\u53e5\u6cd5\u505a\u51fa\u6765\uff0csubject\u662f\u4e00\u4e2a\u9ad8\u5ea6\u4e3a1\u7684\u6811
\u53e5\u5b50\u4e4b\u95f4\u7684\u6210\u5206\u901a\u8fc7\u4e24\u4e24\u7ec4\u5408\u8fd8\u80fd\u505a\u51fa\u65b0\u7684\u9ad8\u5ea6
one-replacement
\u7528one-replacement\u63a2\u6d4b\u9650\u5b9a\u8bcd\u4e4b\u95f4\u7684\u8ddd\u79bb\u5173\u7cfb\uff08\u52a8\u8bcd\u7528did so/did too\uff09
Mika loved the policeman intensively.\nSusan did so half-heartedly.\n*Susan did so the baker.\n
graph TD\n NP --> D\n D --> the\n NP --> N1\n N1 --> AdjP\n AdjP --> big\n N1 --> N2\n N2 --> N3\n N2 --> PP1\n N3 --> N\n N --> book\n N3 --> PP2\n PP2 --> of_poems\n PP1 --> with_the_blue_cover\n
\u52a0\u5165\u4e86bar level\uff0cbook\u4e0eof poems\u6784\u6210\u4e00\u4e2a\u4e2d\u95f4\u6295\u5c04X-bar\uff0c\u6784\u6210\u4e00\u4e2aconstituent\u3002\u4f7f\u5f97\u6bcf\u4e2a\u53e5\u5b50\u90fd\u80fd\u88ab\u753b\u6210\u4e00\u4e2a\u4e8c\u53c9\u6811\u5f62\u5f0f
\u751f\u6210\u53e5\u6cd5\u5b66\u6d3e\uff1a\u4e0a\u4e16\u7eaa\u4e94\u5341\u5e74\u4ee3\u3002classical theory and standard theory\u30021988\u5e74\u63d0\u51fa\u4e86government and binding theory\u3002lexicon, D-S, S-S, PF, LF
"},{"location":"Ling/Syntax/conv_gen/#n-bar","title":"N-bar","text":"\u539f\u672cNP\u6839\u636e\u4e00\u7cfb\u5217\u89c4\u5219\u4e0d\u662f\u4e8c\u53c9\u6811\uff0c\u6bd4\u5982N\u2192
N-bar theory\u8ba4\u4e3a\u53ef\u4ee5\u90fd\u53d8\u6210\u4e8c\u53c9\u6811
\u89c4\u5219\u6bd4\u5982
NP -> Det N'\nN' -> AP N'\nN' -> N PP\n
\u7b2c\u4e00\u6761\u79f0\u4e3a\u4e00\u4e2a\u6700\u5927\u6295\u5c04
"},{"location":"Ling/Syntax/conv_gen/#v-bar","title":"V-bar","text":"VP -> V' // \u9884\u7559\u4e00\u4e2a\u4f4d\u7f6e\u7ed9\u6f5c\u5728\u7684specifier\uff0c\u5373\u4f7f\u6ca1\u6709\nV' -> AdvP V' | V' PP | V' AdvP\nV' -> V(NP)\n
"},{"location":"Ling/Syntax/conv_gen/#abj-bar","title":"Abj-bar","text":"AdjP -> Adj'\nAdj' -> (AdvP) Adj' | Adj' (AdvP)\nAdj' -> Adj(PP)\n
"},{"location":"Ling/Syntax/conv_gen/#p-bar","title":"P-bar","text":"PP -> P'\nP' -> P'(PP) | (AdvP)P'\nP' -> P(NP)\n
\u4e2d\u5fc3\u8bcdX \u2192 \u4e2d\u95f4\u6295\u5c04X\u2019 \u2192 \u6700\u5927\u6295\u5c04XP\u3002\u4e0d\u80fd\u76f4\u63a5\u5230XP\uff0c\u4e00\u5b9a\u8981\u6709\u4e2d\u95f4\u6295\u5c04
"},{"location":"Ling/Syntax/conv_gen/#parameter-of-word-orders","title":"Parameter of Word Orders \u7ba1\u7ea6\u8bba\uff0c \u539f\u5219\u4e0e\u53c2\u6570\u7406\u8bba","text":"\u6839\u636eX-bar\u7406\u8bba\uff0c\u53ef\u4ee5\u5bf9\u4e00\u4e9b\u8bed\u8a00\u7684\u4e0d\u540c\u8bed\u5e8f\uff08\u5982SVO\uff0cSOV\u7b49\uff09\u7ed9\u51fa\u8bed\u6cd5\u53c2\u6570\u5316\u89e3\u91ca
specifier\u548ccomplement\u53ef\u4ee5\u51fa\u73b0\u5728\u5176sister\u7684\u4e24\u4fa7\uff0c\u8fd9\u79cd\u6295\u5c04\u7684\u5de6\u53f3\u533a\u522b\u88ab\u79f0\u4e3aparameter setting
"},{"location":"Ling/Syntax/conv_gen/#_2","title":"\u753b\u6811\u7684","text":"head movement: movement from a head to another head position
\u53e5\u5b50\u53ef\u4ee5\u53d1\u751fmovement\u7684\u6807\u5fd7
"},{"location":"Ling/Syntax/conv_gen/#-reading","title":"- \u4e00\u4e2a\u53e5\u6cd5\u7ed3\u6784\u5177\u6709\u4e24\u79cdreading","text":"shortest movement
shortest: let the path of a movement be the set of nodes that dominate the original position of the moved item, and do not dominate the leading site.
"},{"location":"Ling/Syntax/ud_sud/","title":"\u4f9d\u5b58\u53e5\u6cd5 UD & SUD","text":"In full spelling, Universal Dependency gammar and Surface Syntax Universal Dependency grammar.
"},{"location":"Ling/Syntax/ud_sud/#tools","title":"Tools","text":"AllenNLP Demo CoreNLP Tool
"},{"location":"Ling/Syntax/ud_sud/#concepts","title":"Concepts","text":"Dependency grammar\u00a0(DG) is an approach to the study of the syntax and grammar of natural languages that is quite distinct from\u00a0phrase structure grammar\u00a0(PSG), which is also known as\u00a0constituency grammar. The modern history of DG begins with\u00a0Lucien Tesni\u00e8re's major oeuvre (1959), whereas the modern history of PSG begins arguably with\u00a0Noam Chomsky's first prominent work (1957).
DG views linguistic structures in terms of a\u00a0one-to-one mapping\u00a0of atomic linguistic units to the nodes in structure, whereas PSG assumes a\u00a0one-to-one-or-more mapping. The distinction is clearly visible when one compares the tree structures. The next trees are taken from the\u00a0Wikipedia article on DG:
"},{"location":"Ling/Syntax/ud_sud/#sud","title":"SUD","text":"[Surface Syntactic Universal Dependencies (SUD) | SUD](https://surfacesyntacticud.github.io/ SUD is an annotation scheme for syntactic dependency treebanks, and has a nearly perfect degree of two-way convertibility with the Universal Dependencies scheme (UD). Contrary to UD, it is based on syntactic criteria (favoring functional heads) and the relations are defined on distributional and functional bases.
"},{"location":"Ling/Syntax/ud_sud/#general-principles-of-sud","title":"General principles of SUD","text":"SUD has 4 specific syntactic relations and a few extended relations: - subj - udep - comp - comp:aux - comp:cleft - comp:obj - comp:obl - comp:pred - mod
"},{"location":"Ling/Syntax/uni_gram/","title":"\u666e\u904d\u8bed\u6cd5 Universal Grammar","text":""},{"location":"Ling/Syntax/uni_gram/#introduction","title":"Introduction","text":"Syntax\u7684\u610f\u4e49\u5728\u4e8e\u627e\u5230\u4e00\u79cdgrammar\uff0c\u80fd\u591f\u751f\u6210\u67d0\u79cd\u8bed\u8a00\u4e2d\u7684\u6240\u6709\u53e5\u5b50\u3002
Grammar\u662f\u57fa\u4e8e\u89c4\u5219\u7684\uff0c\u4e0d\u80fd\u7528high order of statistical approximation to English\u6765\u66ff\u4ee3\u3002
"},{"location":"Ling/Syntax/uni_gram/#basic-linguistics","title":"Basic Linguistics","text":"DFA & Regular language
\u8c13\u8bcd\u903b\u8f91\u3002\u4f46\u6211\u4eec\u4e0d\u5173\u5fc3\u5176\u4e2d\u7684\u8bed\u4e49\uff0c\u53ea\u9700\u5173\u5fc3CFG\u7684\u5f62\u5f0f\u3002
"},{"location":"Ling/Syntax/uni_gram/#phrase-structure-limitation","title":"Phrase Structure & Limitation","text":"\u81ea\u7136\u8bed\u8a00\u7684CFG\uff08\u4ee5\u82f1\u8bed\u4e3a\u4f8b\uff09\u6784\u6210\u8bed\u6cd5\u7684\u57fa\u7840\u90e8\u5206\u3002
\u4f46\u8fd9\u6837\u63cf\u8ff0\u81ea\u7136\u8bed\u8a00\u7684\u5de5\u5177\u8fd8\u662f\u4e0d\u80fd\u751f\u6210\u6240\u6709\u5408\u7406\u7684\u53e5\u5b50\uff0c\u6545\u5f15\u5165a more powerful model combining phrase structure and grammatical transformation\uff0c\u5f97\u5230\u8f6c\u6362-\u751f\u6210\u6587\u6cd5\u3002
"},{"location":"Ling/Syntax/uni_gram/#on-the-goals-of-linguistic-theory","title":"On the Goals of Linguistic Theory","text":"\u4ece\u4e00\u822c\u8bed\u6cd5\u4e2d\u5f52\u7eb3\u51faUG\u7406\u8bba\uff0c\u5bf9UG\u7684\u671f\u671b\u7531\u5f3a\u81f3\u5f31\u4e3a\uff1a
\u5e94\u8be5\u7814\u7a76competence\uff0c\u800c\u975eperformance
"},{"location":"Math/","title":"\u7d22\u5f15","text":"\u672c\u4e13\u680f\u5185\u5bb9\u4e3a\u6570\u5b66\u7b14\u8bb0\uff0c\u5305\u62ec\u4ee5\u4e0b\u5206\u652f\uff1a - \u56fe\u8bba - \u79bb\u6563\u6570\u5b66
"},{"location":"Math/normal_forms/","title":"\u5404\u79cdNormal Forms","text":""},{"location":"Math/normal_forms/#conjunctive-normal-form-cnf","title":"Conjunctive Normal Form (CNF)","text":"conjunction of one or more clauses
(A or ~B or ~C) and (~D or E or F)\n
"},{"location":"Math/normal_forms/#disjunctive-normal-form","title":"Disjunctive Normal Form","text":"\uff08A and ~B and ~C\uff09or (~D and E and F)\n
"},{"location":"Math/normal_forms/#algebraic-normal-form","title":"Algebraic Normal Form","text":"one more terms are combined into terms by AND, and one more terms are combined by XOR
a XOR b XOR (a AND b) XOR (a AND b AND c)\n
"},{"location":"Math/normal_forms/#negation-normal-form-nnf","title":"Negation Normal Form (NNF)","text":"if the negation operator is only applied to variables and the only other allowed Boolean operators are conjunctions and disjunctions
~A and B\n
"},{"location":"Math/normal_forms/#chomsky-normal-form","title":"Chomsky Normal Form","text":"formal language theory \u5047\u7684
A \u2192 BC\nA \u2192 a\nS \u2192 \u03b5\n
Category:Normal forms (logic)
"},{"location":"Math/questions/","title":"\u96f6\u6563\u7684\u9898","text":"RHS\u6210\u7acb\u7684\u6761\u4ef6\u662f \u5fc5\u987b\u6240\u6709x\u90fd\u4f7fP(x)\u4e0d\u6210\u7acb\uff0c\u624d\u80fd\u4e0d\u7ba1Q(y)\u662f\u5426\u6210\u7acb \u6216\u6240\u6709P(x)\u90fd\u6210\u7acb\uff0c\u4e14Q(y)\u6210\u7acb
\u6240\u4ee5\u5f53\\(\\exists x\\)\u4f7fP(x)\u4e3a\u5047\uff0c\u4f46\u662f\u5176\u5b83x\u4f7fp(x)\u4e3a\u771f\uff0c\u4e14\\(\\forall y\\)\u4f7fQ(y)\u4e3a\u5047\u65f6\uff0cLHS\u662f\u771f\u7684\uff0c\u4f46\u662fRHS\u662f\u5047\u7684\uff0c\u6240\u4ee5LHS\\(\\neq\\)RHS.
\u6309\u7167\u8fd9\u4e2a\u53ef\u4ee5\u4e3e\u4e00\u4e2a\u4f8b\u5b50 U = \u81ea\u7136\u6570 P(x) = x \u662f\u5947\u6570 Q(y) = y \u662f\u8d1f\u6570
"},{"location":"Math/Graph/laplace_matrix/","title":"Laplacian Matrix","text":""},{"location":"Math/Graph/laplace_matrix/#basic-properties","title":"Basic Properties","text":"or L = D(degree matrix) - A(adjacency matrix)
"},{"location":"Math/Graph/laplace_matrix/#normalization","title":"Normalization","text":""},{"location":"Math/Graph/laplace_matrix/#eigendecomposition","title":"Eigendecomposition","text":""},{"location":"Math/Graph/laplace_matrix/#gcnlaplace","title":"\u4e3a\u4ec0\u4e48GCN\u8981\u7528\u5230laplace\u77e9\u9635","text":"Laplacian matrix
"},{"location":"Other/","title":"\u7d22\u5f15","text":"TODO\uff08\u8fd8\u6ca1\u5199\uff09
"},{"location":"Other/apa/","title":"APA Format","text":"\u6211\u559c\u6b22\u7528\u5f15\u6587\u81ea\u52a8\u751f\u6210\u5668\uff0c\u63a8\u8350\u51e0\u4e2a
APA\u683c\u5f0f\u6307\u7684\u662f\u7f8e\u56fd\u5fc3\u7406\u5b66\u4f1a\uff08American Psychological Association\uff0c\u7b80\u79f0APA\uff09\u51fa\u7248\u7684\u300a\u7f8e\u56fd\u5fc3\u7406\u534f\u4f1a\u51fa\u7248\u624b\u518c\u300b\uff08Publication Manual of the American Psychological Association\uff09\u3002\u5b83\u8d77\u6e90\u4e8e1929\u5e74\uff0c\u5230\u76ee\u524d\u4e3a\u6b62\u5df2\u7ecf\u66f4\u65b0\u81f3\u7b2c\u4e03\u7248\uff0c\u603b\u9875\u6570\u4e5f\u5df2\u7ecf\u8d85\u8fc7400\u9875\uff0c\u91cc\u9762\u8be6\u7ec6\u89c4\u8303\u4e86\u6587\u7ae0\u7684\u9875\u9762\u683c\u5f0f\uff08\u884c\u95f4\u8ddd\u3001\u5b57\u4f53\u3001\u5b57\u53f7\u3001\u9875\u8fb9\u8ddd\u7b49\u7b49\uff09\u3001\u56fe\u8868\u8868\u683c\\\u53c2\u8003\u6587\u732e\u7b49\u7b49\uff0c\u6781\u4e3a\u5168\u9762\u3002APA\u4e3b\u8981\u7528\u4e8e\u5fc3\u7406\u3001\u6559\u80b2\u53ca\u793e\u4f1a\u79d1\u5b66\u7b49\u5b66\u79d1\u3002\u5176\u89c4\u8303\u683c\u5f0f\u4e3b\u8981\u5305\u62ec\u6587\u5185\u6587\u732e\u5f15\u7528\uff08Reference Citations in Text\uff09\u548c\u6587\u672b\u53c2\u8003\u6587\u732e\u5217\u8868\uff08Reference List\uff09\u4e24\u5927\u90e8\u5206\u3002
APA\u683c\u5f0f\u5f3a\u8c03\u51fa\u7248\u7269\u7684\u5e74\u4ee3\uff08Time of the Publication Year\uff09\u800c\u4e0d\u5927\u6ce8\u91cd\u539f\u6587\u4f5c\u8005\u7684\u59d3\u540d\u3002\u5f15\u6587\u65f6\u5e38\u5c06\u51fa\u7248\u5e74\u4ee3\u7f6e\u4e8e\u4f5c\u8005\u7f29\u5199\u7684\u540d\uff08the Initial of Author\u2019s First Name\uff09\u4e4b\u524d\u3002
\u4e00\u3001\u6587\u5185\u6587\u732e\u5f15\u7528\uff08ReferenceCitations in Text\uff09
1.\u5355\u4e00\u4f5c\u8005
\u683c\u5f0f\u5e94\u4e3a\u201c\uff08\u4f5c\u8005\u59d3\u6c0f\uff08\u975e\u9996\u5b57\u6bcd\uff09\uff0c\u53d1\u8868\u5e74\u4efd\uff09\u201d\u3002\u82e5\u4f5c\u8005\u59d3\u540d\u5728\u6587\u7ae0\u4e2d\u5df2\u88ab\u63d0\u53ca\uff0c\u53ea\u9700\u6807\u51fa\u5e74\u4efd\u5c31\u597d\uff08\u82e5\u9700\u8981\u53ef\u52a0\u4e0a\u9875\u6570\uff09\uff0c\u4ecd\u9700\u4f7f\u7528\u62ec\u53f7\u3002\u591a\u4f4d\u4f5c\u8005\u4ee5\u4e0a\u540c\u7406\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, 2005). Pauling (2005) discovered a possible genetic cause of alcoholism.
2.\u4e24\u4f4d\u4f5c\u8005
\u4f5c\u8005\u59d3\u6c0f\u5fc5\u987b\u4ee5\u4ed6\u4eec\u7684\u540d\u5b57\u5728\u5176\u53d1\u8868\u6587\u7ae0\u5185\u7684\u987a\u5e8f\u6765\u6392\u5e8f\u3002\u82e5\u4e24\u4e2a\u4f5c\u8005\u90fd\u5728\u62ec\u53f7\u5185\u5f15\u7528\uff0c\u540d\u5b57\u4e2d\u95f4\u9700\u52a0\u4e0a\u201c&\u201d\u7b26\u53f7\uff1b\u82e5\u4e0d\u5728\u62ec\u53f7\u5185\u5219\u4f7f\u7528\u201cand\u201d\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling & Liu, 2005). Pauling and Liu (2005) discovered a possible genetic cause of alcoholism.
3.\u4e09\u81f3\u4e94\u4f4d\u4f5c\u8005
\u7b2c\u4e00\u6b21\u5f15\u7528\u65f6\u9700\u5217\u4e3e\u5168\u90e8\u7684\u4f5c\u8005\uff0c\u5f80\u540e\u82e5\u5f15\u7528\u76f8\u540c\u7684\u6587\u732e\uff0c\u53ea\u9700\u4e3e\u51fa\u6700\u4e3b\u8981\u7684\u4f5c\u8005\uff0c\u518d\u52a0\u4e0a\u201cet al.\u201d\u3002\u4f46\u662f\uff0c\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0c\u5168\u90e8\u4f5c\u8005\u7684\u59d3\u540d\u7686\u987b\u5217\u4e3e\u51fa\u6765\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, Liu, & Guo, 2005). Pauling, Liu, and Guo (2005) conducted a study that discovered a possible genetic cause of alcoholism. Pauling et al. (2005) discovered a possible genetic cause of alcoholism. A recent study found a possible genetic cause of alcoholism (Pauling et al., 2005).
4.\u516d\u4f4d\u4f5c\u8005\u4ee5\u4e0a
\u4e3e\u51fa\u7b2c\u4e00\u4f4d\u4f5c\u8005\u5373\u53ef\uff0c\u683c\u5f0f\u5e94\u4e3a\u201c\uff08\u4f5c\u8005\u00a0et al.\uff0c\u5e74\u4efd\uff09\u201d\u3002\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0c\u5168\u90e8\u4f5c\u8005\u7684\u59d3\u540d\u7686\u987b\u5217\u4e3e\u51fa\u6765\u3002\u4f8b\u5982\uff1a
Pauling et al. (2005) discovered a possible genetic cause of alcoholism.
5.\u591a\u7bc7\u6587\u732e\uff0c\u540c\u4e00\u4f5c\u8005
\u82e5\u4e00\u4f5c\u8005\u6709\u591a\u7bc7\u4f60\u60f3\u5f15\u7528\u7684\u6587\u732e\uff0c\u53ea\u9700\u7528\u9017\u53f7\u6765\u533a\u9694\u4f5c\u54c1\u7684\u53d1\u8868\u5e74\u4efd\uff08\u6700\u65e9\u5230\u6700\u665a\u4f9d\u5e8f\u6392\u5217\uff09\u3002\u82e5\u591a\u7bc7\u6587\u732e\u5728\u540c\u4e00\u5e74\u5185\u53d1\u8868\uff0c\u8bf7\u5728\u5e74\u4efd\u540e\u9762\u52a0\u4e0aa\u3001b\u3001c\u2026\u2026\u7b49\u6807\u6ce8\u3002\uff08\u6309\uff1aabc\u7684\u4f7f\u7528\u9700\u4e0e\u53c2\u8003\u6587\u732e\u90e8\u5206\u6709\u6240\u5bf9\u5e94\uff0c\u800c\u8fd9\u4e9b\u6587\u732e\u7684\u7f16\u6392\u4ee5\u6807\u9898\u540d\u79f0\u7684\u5b57\u6bcd\u6765\u51b3\u5b9a\u3002\uff09\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Pauling, 2004, 2005a, 2005b). Pauling (2004, 2005a, 2005b) conducted a study that discovered a possible genetic cause of alcoholism
6.\u591a\u7bc7\u6587\u732e\uff0c\u591a\u4f4d\u4f5c\u8005
\u6839\u636e\u4e0a\u4e00\u4e2a\u7684\u89c4\u5219\uff0c\u5e76\u4e14\u4f7f\u7528\u5206\u53f7\u9694\u5f00\u3002\u6392\u5e8f\u5148\u4f9d\u7167\u4f5c\u8005\u59d3\u6c0f\u7684\u5b57\u6bcd\uff0c\u63a5\u7740\u662f\u53d1\u8868\u5e74\u4efd\u3002\u4f8b\u5982\uff1a
A recent study found a possible genetic cause of alcoholism (Alford, 1995; Pauling, 2004, 2005; Sirkis, 2003)
7.\u76f4\u63a5\u5f15\u8ff0
\u683c\u5f0f\u4e0e\u524d\u8ff0\u65e0\u4e0d\u540c\uff0c\u4e00\u6837\u4e3a\u201c\uff08\u4f5c\u8005\uff0c\u5e74\u4efd\uff0c\u9875\u6570\uff09\u201d\u3002\u4f8b\u5982\uff1a
When asked why his behavior had changed so dramatically, Max simply said \u201cI think it\u2019s the reinforcement\u201d (Pauling, 2004, p. 69).
\u4e8c\u3001\u6587\u672b\u53c2\u8003\u6587\u732e\u5217\u8868\uff08Reference List\uff09
\u5728\u53c2\u8003\u6587\u732e\u90e8\u5206\uff0cAPA\u683c\u5f0f\u89c4\u5b9a\u90e8\u5206\u7684\u4eba\u540d\u5fc5\u987b\u4ee5\u59d3\uff08Family name\uff09\u7684\u5b57\u6bcd\u987a\u5e8f\u6765\u6392\u5217\uff0c\u5305\u62ec\u540d\uff08first name\uff09\u7684\u524d\u7f00\u3002
1.\u5355\u4e00\u4f5c\u8005\u8457\u4f5c\u7684\u4e66\u7c4d\u3002\u4f8b\u5982\uff1a
Sheril, R. D. (1956).\u00a0The terrifying future: Contemplating color television. San Diego: Halstead.
2.\u4e24\u4f4d\u4f5c\u8005\u4ee5\u4e0a\u5408\u8457\u7684\u4e66\u7c4d\u3002\u4f8b\u5982\uff1a
Smith, J., & Peter, Q. (1992).\u00a0Hairball: An intensive peek behind the surface of an enigma. Hamilton, ON: McMaster University Press.
3.\u6587\u96c6\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Mcdonalds, A. (1993). Practical methods for the apprehension and sustained containment of supernatural entities. In G. L. Yeager (Ed.),\u00a0Paranormal and occult studies: Case studies in application\u00a0(pp. 42\u201364). London: OtherWorld Books.
4.\u671f\u520a\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Crackton, P. (1987). The Loonie: God\u2019s long-awaited gift to colourful pocket change?\u00a0Canadian Change, 64(7), 34\u201337.
5.\u6708\u520a\u6742\u5fd7\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Henry, W. A., III. (1990, April 9). Making the grade in today\u2019s schools.\u00a0Time, 135, 28-31.
6.\u62a5\u7eb8\u4e2d\u7684\u6587\u7ae0\u3002\u4f8b\u5982\uff1a
Wrong, M. (2005, August 17). Misquotes are \u201cProblematastic\u201d says Mayor.\u00a0Toronto Sol.,\u00a04.
7.\u653f\u5e9c\u5b98\u65b9\u6587\u732e
Revenue Canada. (2001).\u00a0Advanced gouging: Manual for employees\u00a0(MP 65\u2013347/1124). Ottawa: Minister of Immigration and Revenue.
8.\u9488\u5bf9\u7535\u5b50\u6587\u732e\u3001\u7f51\u7ad9\u548c\u7ebf\u4e0a\u6587\u7ae0\uff0cAPA\u683c\u5f0f\u7684\u7f51\u7ad9\u4e0a\u6709\u8ba2\u5b9a\u4e00\u4e9b\u57fa\u672c\u7684\u89c4\u5219\uff0c\u7b2c\u4e00\u5c31\u662f\u63d0\u4f9b\u8bfb\u8005\u8be6\u7ec6\u7684\u6587\u732e\u5185\u5bb9\u6765\u6e90\uff0c\u7b2c\u4e8c\u4e3a\u63d0\u4f9b\u5176\u6709\u6548\u7684\u53c2\u8003\u6765\u6e90\u3002
\u2474\u00a0\u7f51\u7edc\u6587\u7ae0\u7684\u6253\u5370\u7248\u672c
Marlowe, P., Spade, S., & Chan, C. (2001). Detective work and the benefits of colour versus black and white [Electronic version].Journal of Pointless Research, 11,123\u2013124.
\u2475\u00a0\u7535\u5b50\u671f\u520a\u7684\u6587\u7ae0\uff08\u53ea\u6709\u7f51\u7edc\u7248\u7684\u671f\u520a\uff09
Blofeld, E. S. (1994, March 1). Expressing oneself through Persian cats and modern architecture.Felines & Felons, 4,Article 0046g. Retrieved October 3, 1999, from\u00a0\u7f51\u9875\u5730\u5740.
\u2476\u00a0\u7535\u5b50\u77ed\u4fe1\uff08newsletter\uff09\u7684\u6587\u7ae0
Paradise, S., Moriarty, D., Marx, C., Lee, O. B., Hassel, E., et al. (1957, July). Portrayals of fictional characters in reality-based popular writing: Project update.Off the beaten path, 7(3). Retrieved October 3, 1999, from\u00a0\u7f51\u9875\u5730\u5740.
\u2477\u00a0\u5355\u7bc7\u7ebf\u4e0a\u6587\u732e\uff08\u65e0\u4f5c\u8005\u53ca\u8457\u4f5c\u65e5\u671f\uff09
What I did today.(n.d.). Retrieved August 21, 2002, from\u00a0\u7f51\u9875\u5730\u5740.
\u2478\u00a0\u4ece\u5927\u5b66\u8bfe\u7a0b\u6216\u7cfb\u4e0a\u7f51\u7ad9\u53d6\u5f97\u7684\u6587\u732e
Rogers, B. (2078).Faster-than-light travel: What we\u2019ve learned in the first twenty years.Retrieved August 24, 2079, from Mars University, Institute for Martian Studies Web site:\u00a0\u7f51\u9875\u5730\u5740.
\u2479\u00a0\u4ece\u6570\u636e\u5e93\u641c\u5bfb\u7684\u671f\u520a\u6587\u7ae0\u7684\u7535\u5b50\u590d\u5236\u7248\u672c\uff083\u81f35\u4f4d\u4f5c\u8005\uff09
Costanza, G., Seinfeld, J., Benes, E., Kramer, C., & Peterman, J. (1993).\u00a0Minuti\u00e6 and insignificant observations from the nineteen-nineties.Journal about Nothing, 52,475\u2013649. Retrieved October 31, 1999,\u00a0from NoTHINGJournals database.
\u247a\u00a0\u7535\u5b50\u90ae\u4ef6\u6216\u5176\u4ed6\u4e2a\u4eba\u901a\u8baf\uff08\u4e0d\u51fa\u73b0\u5728\u53c2\u8003\u6587\u732e\u5217\u8868\u4e2d\uff0c\u4ec5\u5728\u6587\u4e2d\u6807\u51fa\uff09\u3002\u4f8b\u5982\uff1a
(A. Monterey, personal communication, September 28, 2001).
9.\u50a8\u5b58\u4e8e\u5149\u789f\u7684\u4e66\u7c4d
Nix, G. (2002).\u00a0Lirael, Daughter of the Clayr\u00a0[CD].\u00a0New York: Random House/Listening Library.
10.\u50a8\u5b58\u4e8e\u5f55\u97f3\u5e26\u7684\u4e66\u7c4d
Nix, G. (2002).\u00a0Lirael, Daughter of the Clayr\u00a0[Cassette Recording No. 1999-1999-1999]\u3002New York: Random House/Listening Library.
APA\u683c\u5f0f\u8303\u6587\u53ef\u6d4f\u89c8\u7f51\u9875\uff1a
MLA Sample Essay
\u5176\u8be6\u7ec6\u7684\u4ecb\u7ecd\u53ef\u53c2\u770b\u7f8e\u56fd\u4f5b\u8499\u7279\u5927\u5b66\u56fe\u4e66\u9986\u5927\u536b\u2022W\u2022\u8c6a\u7eaa\u5ff5\u56fe\u4e66\u9986\uff08David W. Howe Memorial Library of THE UNIVERSITY OF VERMONT Libraries\uff09\u7f51\u7ad9\u4e0a\u7684\u201cAPA (American Psychological Association) Style\u201d\u7f51\u9875\uff08\u7f51\u5740\uff1a
APA (American Psychological Association) Style | Howe Library
"},{"location":"Other/nlp_resources/","title":"DL & NLP Resources","text":""},{"location":"Other/nlp_resources/#machine-learning-theory","title":"Machine Learning Theory","text":"Google\u7684\u4e00\u4e2a\u6559\u7a0b\uff0c\u91cc\u9762\u7684playground\u505a\u5f97\u6bd4\u8f83\u76f4\u89c2\uff0c\u65e0\u9700\u4ee3\u7801
Machine Learning \u00a0|\u00a0 Google for Developers
"},{"location":"Other/nlp_resources/#machine-learning-technology","title":"Machine Learning Technology","text":"TODO
"},{"location":"Other/nlp_resources/#deep-learning-theory","title":"Deep Learning Theory","text":"TODO
"},{"location":"Other/nlp_resources/#deep-learning-technology","title":"Deep Learning Technology","text":"Pytorch\u6559\u7a0b\uff0c\u53ef\u4ee5\u770b\u7740\u4ee3\u7801\u624b\u6284\u4e00\u4e0b
Welcome to PyTorch Tutorials \u2014 PyTorch Tutorials 2.0.1+cu117 documentation
numpy: numpy 100 exercise
rougier/numpy-100: 100 numpy exercises (with solutions) (github.com)
Pytorch
PyTorch\u6df1\u5ea6\u5b66\u4e60\u5feb\u901f\u5165\u95e8\u6559\u7a0b\uff08\u7edd\u5bf9\u901a\u4fd7\u6613\u61c2\uff01\uff09\u3010\u5c0f\u571f\u5806\u3011_\u54d4\u54e9\u54d4\u54e9_bilibili
Attention-based Models and Transformer
Let's build GPT: from scratch, in code, spelled out. - YouTube
"},{"location":"Other/nlp_resources/#natural-language-processing-theory","title":"Natural Language Processing Theory","text":"Stanford CS224N: NLP with Deep Learning | Winter 2021 | Lecture 1 - Intro & Word Vectors - YouTube
"},{"location":"Other/nlp_resources/#natural-language-processing-technology","title":"Natural language processing technology","text":"Stanford CS 224N | Natural Language Processing with Deep Learning
"},{"location":"Other/nlp_resources/#reinforcement-learning","title":"Reinforcement Learning","text":"\u8611\u83c7\u4e66EasyRL (datawhalechina.github.io)
Codes:
boyu-ai/Hands-on-RL: https://hrl.boyuai.com/ (github.com) datawhalechina/easy-rl: \u5f3a\u5316\u5b66\u4e60\u4e2d\u6587\u6559\u7a0b\uff08\u8611\u83c7\u4e66\uff09\uff0c\u5728\u7ebf\u9605\u8bfb\u5730\u5740\uff1ahttps://datawhalechina.github.io/easy-rl/
"},{"location":"Other/nlp_resources/#computer-vision","title":"Computer Vision","text":"Computer Vision | Universit\u00e4t T\u00fcbingen (uni-tuebingen.de)
"},{"location":"Other/tools/","title":"\u6211\u7684\u5de5\u5177\u7bb1\uff01","text":"\u8bb0\u5f55\u4e00\u70b9\u597d\u7528\u7684\u5de5\u5177\u54c8
"},{"location":"Other/tools/#workflow","title":"\u6211\u7684workflow","text":""},{"location":"Other/tools/#notionobsidian","title":"\u9009\u62e9Notion\u548cObsidian","text":"\u5148\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7ed3\u8bba
\u4f18\u70b9/\u5de5\u5177 Notion Obsidian \u8bed\u6cd5 \u81ea\u5df1\u7684\u4e00\u5957\u8bed\u6cd5\uff0c\u90e8\u5206\u662fmarkdown \u7eafmarkdown \u4e66\u5199\u901f\u5ea6 \u6162 \u5feb \u6587\u6863\u6574\u9f50\u7a0b\u5ea6 \u9ad8 \u4f4e \u90e8\u7f72\u5230mkdocs\u96be\u6613 \u6613\uff0c\u53ef\u76f4\u63a5\u7528 \u96be\uff0c\u9700\u8c03\u6574\u5f88\u591a\u683c\u5f0f \u5bfc\u51fa\u4e2d\u6587\u652f\u6301\u7a0b\u5ea6 \u53ea\u6709\u4e09\u79cd\u5b57\u4f53\uff0c\u90e8\u5206\u4e2d\u6587\u7f3a\u5b57 \u5b57\u4f53\u591a\uff0c\u652f\u6301\u6bd4\u8f83\u597d\u76ee\u524d\u6211\u9009\u62e9\u7684workflow
graph TD\n \u542c\u5199 --> Notion \n Notion -- \u6709\u65f6\u95f4 --> Obsidian\n \u6709\u65f6\u95f4\u6162\u6162\u5199 --> Obsidian\n Obsidian -- \u4f7f\u7528\u540c\u4e00\u6587\u4ef6\u5939 --> mkdocs\n
Obsidian to mkdocs 1. \u56fe\u7247\u8def\u5f84\u95ee\u9898\uff1a \u9700\u8981\u5728\u8bbe\u7f6e\u4e2d\u5173\u95ed\u4f7f\u7528wiki\u8def\u5f84\uff0c\u4fdd\u8bc1\u6240\u6709\u56fe\u7247\u90fd\u7528md\u8bed\u6cd5![]()
\u4e14\u9700\u8981\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\uff0c\u5373\u524d\u9762\u52a0./
\u7684\u90a3\u79cd
TODO
"},{"location":"Other/tools/#_2","title":"\u6587\u732e\u7ba1\u7406\u5de5\u5177","text":"TODO
\u5176\u5b9e\u4ed3\u5e93\u91cc\u672c\u6587\u4ef6\u5939\u4e0b\u7684asset\u91cc\u73b0\u5728\u6709\u4e2a\u600e\u4e48\u914d\u7f6ezotero\u7684ppt\uff0c\u592a\u61d2\u6ca1\u65f6\u95f4\u6574\u8fc7\u6765\uff0c\u53ef\u4ee5\u5148\u53bb\u4ed3\u5e93\u91cc\u627e\u627eorz
"},{"location":"Other/tools/#_3","title":"\u96f6\u6563\u5de5\u5177","text":""},{"location":"Other/tools/#_4","title":"\u4e8c\u7ef4\u7801\u751f\u6210\u5668","text":"\u751f\u6210\u957f\u5f97\u4e0d\u50cf\u4e8c\u7ef4\u7801\u7684\u4e8c\u7ef4\u7801 \u76f4\u63a5\u626b\u4e0b\u9762\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u8fdb\u5165\u7f51\u7ad9
"},{"location":"Other/zotero/","title":"Zotero","text":""}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 82ed4fe2b4cd50a45c1e4c10ef1b2a8a2ab3dadc..d392fc4b472482c402c4d331759754df1c9fb75c 100644 GIT binary patch delta 15 WcmZ3@wwjGizMF$Xa_vSoRb~JoOasUO delta 15 WcmZ3@wwjGizMF%CWz9x5Rb~Jn$pf+g