Skip to main content
Erschienen in:
Buchtitelbild

2019 | OriginalPaper | Buchkapitel

Learning to Generate Comments for API-Based Code Snippets

verfasst von : Yangyang Lu, Zelong Zhao, Ge Li, Zhi Jin

Erschienen in: Software Engineering and Methodology for Emerging Domains

Verlag: Springer Singapore

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

Comments play an important role in software developments. They can not only improve the readability and maintainability of source code, but also provide significant resource for software reuse. However, it is common that lots of code in software projects lacks of comments. Automatic comment generation is proposed to address this issue. In this paper, we present an end-to-end approach to generate comments for API-based code snippets automatically. It takes API sequences as the core semantic representations of method-level API-based code snippets and generates comments from API sequences with sequence-to-sequence neural models. In our evaluation, we extract 217K pairs of code snippets and comments from Java projects to construct the dataset. Finally, our approach gains 36.48% BLEU-4 score and 9.90% accuracy on the test set. We also do case studies on generated comments, which presents that our approach generates reasonable and effective comments for API-based code snippets.

Sie haben noch keine Lizenz? Dann Informieren Sie sich jetzt über unsere Produkte:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Literatur
1.
Zurück zum Zitat Abid, N.J., Dragan, N., Collard, M.L., Maletic, J.I.: Using stereotypes in the automatic generation of natural language summaries for C++ methods. In: 2015 IEEE International Conference on Software Maintenance and Evolution (ICSME), pp. 561–565. IEEE (2015) Abid, N.J., Dragan, N., Collard, M.L., Maletic, J.I.: Using stereotypes in the automatic generation of natural language summaries for C++ methods. In: 2015 IEEE International Conference on Software Maintenance and Evolution (ICSME), pp. 561–565. IEEE (2015)
2.
Zurück zum Zitat Allamanis, M., Barr, E.T., Bird, C., Sutton, C.: Suggesting accurate method and class names. In: Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering, pp. 38–49. ACM (2015) Allamanis, M., Barr, E.T., Bird, C., Sutton, C.: Suggesting accurate method and class names. In: Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering, pp. 38–49. ACM (2015)
3.
Zurück zum Zitat Allamanis, M., Peng, H., Sutton, C.: A convolutional attention network for extreme summarization of source code. In: International Conference on Machine Learning, pp. 2091–2100 (2016) Allamanis, M., Peng, H., Sutton, C.: A convolutional attention network for extreme summarization of source code. In: International Conference on Machine Learning, pp. 2091–2100 (2016)
4.
Zurück zum Zitat Bahdanau, D., Cho, K., Bengio, Y.: Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 (2014) Bahdanau, D., Cho, K., Bengio, Y.: Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:​1409.​0473 (2014)
5.
Zurück zum Zitat Buse, R.P., Weimer, W.R.: Automatic documentation inference for exceptions. In: Proceedings of the 2008 International Symposium on Software Testing and Analysis, pp. 273–282. Citeseer (2008) Buse, R.P., Weimer, W.R.: Automatic documentation inference for exceptions. In: Proceedings of the 2008 International Symposium on Software Testing and Analysis, pp. 273–282. Citeseer (2008)
6.
Zurück zum Zitat Cho, K., Van Merriënboer, B., Bahdanau, D., Bengio, Y.: On the properties of neural machine translation: encoder-decoder approaches. arXiv preprint arXiv:1409.1259 (2014) Cho, K., Van Merriënboer, B., Bahdanau, D., Bengio, Y.: On the properties of neural machine translation: encoder-decoder approaches. arXiv preprint arXiv:​1409.​1259 (2014)
7.
Zurück zum Zitat Cho, K., et al.: Learning phrase representations using RNN encoder-decoder for statistical machine translation. arXiv preprint arXiv:1406.1078 (2014) Cho, K., et al.: Learning phrase representations using RNN encoder-decoder for statistical machine translation. arXiv preprint arXiv:​1406.​1078 (2014)
8.
Zurück zum Zitat Haiduc, S., Aponte, J., Marcus, A.: Supporting program comprehension with source code summarization. In: Proceedings of the 32nd ACM/IEEE International Conference on Software Engineering, vol. 2, pp. 223–226. ACM (2010) Haiduc, S., Aponte, J., Marcus, A.: Supporting program comprehension with source code summarization. In: Proceedings of the 32nd ACM/IEEE International Conference on Software Engineering, vol. 2, pp. 223–226. ACM (2010)
9.
Zurück zum Zitat Haije, T., Intelligentie, B.O.K., Gavves, E., Heuer, H.: Automatic comment generation using a neural translation model. Inf. Softw. Technol. 55(3), 258–268 (2016) Haije, T., Intelligentie, B.O.K., Gavves, E., Heuer, H.: Automatic comment generation using a neural translation model. Inf. Softw. Technol. 55(3), 258–268 (2016)
10.
Zurück zum Zitat Hill, E., Pollock, L., Vijay-Shanker, K.: Automatically capturing source code context of NL-queries for software maintenance and reuse. In: Proceedings of the 31st International Conference on Software Engineering, pp. 232–242. IEEE Computer Society (2009) Hill, E., Pollock, L., Vijay-Shanker, K.: Automatically capturing source code context of NL-queries for software maintenance and reuse. In: Proceedings of the 31st International Conference on Software Engineering, pp. 232–242. IEEE Computer Society (2009)
11.
Zurück zum Zitat Iyer, S., Konstas, I., Cheung, A., Zettlemoyer, L.: Summarizing source code using a neural attention model. In: Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics. Long Papers, vol. 1, pp. 2073–2083 (2016) Iyer, S., Konstas, I., Cheung, A., Zettlemoyer, L.: Summarizing source code using a neural attention model. In: Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics. Long Papers, vol. 1, pp. 2073–2083 (2016)
12.
Zurück zum Zitat Kajko-Mattsson, M.: A survey of documentation practice within corrective maintenance. Empirical Softw. Eng. 10(1), 31–55 (2005)CrossRef Kajko-Mattsson, M.: A survey of documentation practice within corrective maintenance. Empirical Softw. Eng. 10(1), 31–55 (2005)CrossRef
13.
Zurück zum Zitat McBurney, P.W., McMillan, C.: Automatic documentation generation via source code summarization of method context. In: Proceedings of the 22nd International Conference on Program Comprehension, pp. 279–290. ACM (2014) McBurney, P.W., McMillan, C.: Automatic documentation generation via source code summarization of method context. In: Proceedings of the 22nd International Conference on Program Comprehension, pp. 279–290. ACM (2014)
14.
Zurück zum Zitat Montandon, J.E., Borges, H., Felix, D., Valente, M.T.: Documenting APIs with examples: lessons learned with the apiminer platform. In: 2013 20th Working Conference on Reverse Engineering (WCRE), pp. 401–408. IEEE (2013) Montandon, J.E., Borges, H., Felix, D., Valente, M.T.: Documenting APIs with examples: lessons learned with the apiminer platform. In: 2013 20th Working Conference on Reverse Engineering (WCRE), pp. 401–408. IEEE (2013)
15.
Zurück zum Zitat Movshovitz-Attias, D., Cohen, W.W.: Natural language models for predicting programming comments. In: Proceedings of the 51st Annual Meeting of the Association for Computational Linguistics. Short Papers, vol. 2, vol. 2, pp. 35–40 (2013) Movshovitz-Attias, D., Cohen, W.W.: Natural language models for predicting programming comments. In: Proceedings of the 51st Annual Meeting of the Association for Computational Linguistics. Short Papers, vol. 2, vol. 2, pp. 35–40 (2013)
16.
Zurück zum Zitat Oda, Y., et al.: Learning to generate pseudo-code from source code using statistical machine translation (t). In: 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE), pp. 574–584. IEEE (2015) Oda, Y., et al.: Learning to generate pseudo-code from source code using statistical machine translation (t). In: 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE), pp. 574–584. IEEE (2015)
17.
Zurück zum Zitat Papineni, K., Roukos, S., Ward, T., Zhu, W.J.: Bleu: a method for automatic evaluation of machine translation. In: Proceedings of the 40th annual meeting on association for computational linguistics, pp. 311–318. Association for Computational Linguistics (2002) Papineni, K., Roukos, S., Ward, T., Zhu, W.J.: Bleu: a method for automatic evaluation of machine translation. In: Proceedings of the 40th annual meeting on association for computational linguistics, pp. 311–318. Association for Computational Linguistics (2002)
18.
Zurück zum Zitat Raghothaman, M., Wei, Y., Hamadi, Y.: Swim: synthesizing what i mean-code search and idiomatic snippet synthesis. In: 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE), pp. 357–367. IEEE (2016) Raghothaman, M., Wei, Y., Hamadi, Y.: Swim: synthesizing what i mean-code search and idiomatic snippet synthesis. In: 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE), pp. 357–367. IEEE (2016)
19.
Zurück zum Zitat de Souza, S.C.B., Anquetil, N., de Oliveira, K.M.: A study of the documentation essential to software maintenance. In: Proceedings of the 23rd Annual International Conference on Design of Communication: Documenting & Designing for Pervasive Information, pp. 68–75. ACM (2005) de Souza, S.C.B., Anquetil, N., de Oliveira, K.M.: A study of the documentation essential to software maintenance. In: Proceedings of the 23rd Annual International Conference on Design of Communication: Documenting & Designing for Pervasive Information, pp. 68–75. ACM (2005)
20.
Zurück zum Zitat Sridhara, G., Hill, E., Muppaneni, D., Pollock, L., Vijay-Shanker, K.: Towards automatically generating summary comments for java methods. In: Proceedings of the IEEE/ACM International Conference on Automated Software Engineering, pp. 43–52. ACM (2010) Sridhara, G., Hill, E., Muppaneni, D., Pollock, L., Vijay-Shanker, K.: Towards automatically generating summary comments for java methods. In: Proceedings of the IEEE/ACM International Conference on Automated Software Engineering, pp. 43–52. ACM (2010)
21.
Zurück zum Zitat Takang, A.A., Grubb, P.A., Macredie, R.D.: The effects of comments and identifier names on program comprehensibility: an experimental investigation. J. Prog. Lang. 4(3), 143–167 (1996) Takang, A.A., Grubb, P.A., Macredie, R.D.: The effects of comments and identifier names on program comprehensibility: an experimental investigation. J. Prog. Lang. 4(3), 143–167 (1996)
22.
Zurück zum Zitat Tenny, T.: Program readability: procedures versus comments. IEEE Trans. Software Eng. 14(9), 1271–1279 (1988)CrossRef Tenny, T.: Program readability: procedures versus comments. IEEE Trans. Software Eng. 14(9), 1271–1279 (1988)CrossRef
23.
Zurück zum Zitat Thung, F., Lo, D., Lawall, J.: Automated library recommendation. In: 2013 20th Working Conference on Reverse Engineering (WCRE), pp. 182–191. IEEE (2013) Thung, F., Lo, D., Lawall, J.: Automated library recommendation. In: 2013 20th Working Conference on Reverse Engineering (WCRE), pp. 182–191. IEEE (2013)
24.
Zurück zum Zitat Wong, E., Liu, T., Tan, L.: Clocom: mining existing source code for automatic comment generation. In: 2015 IEEE 22nd International Conference on Software Analysis, Evolution, and Reengineering (SANER), pp. 380–389. IEEE (2015) Wong, E., Liu, T., Tan, L.: Clocom: mining existing source code for automatic comment generation. In: 2015 IEEE 22nd International Conference on Software Analysis, Evolution, and Reengineering (SANER), pp. 380–389. IEEE (2015)
25.
Zurück zum Zitat Wong, E., Yang, J., Tan, L.: Autocomment: mining question and answer sites for automatic comment generation. In: 2013 28th IEEE/ACM International Conference on Automated Software Engineering (ASE), pp. 562–567. IEEE (2013) Wong, E., Yang, J., Tan, L.: Autocomment: mining question and answer sites for automatic comment generation. In: 2013 28th IEEE/ACM International Conference on Automated Software Engineering (ASE), pp. 562–567. IEEE (2013)
26.
Zurück zum Zitat Woodfield, S.N., Dunsmore, H.E., Shen, V.Y.: The effect of modularization and comments on program comprehension. In: Proceedings of the 5th International Conference on Software Engineering, pp. 215–223. IEEE Press (1981) Woodfield, S.N., Dunsmore, H.E., Shen, V.Y.: The effect of modularization and comments on program comprehension. In: Proceedings of the 5th International Conference on Software Engineering, pp. 215–223. IEEE Press (1981)
27.
Zurück zum Zitat Zhang, S., Zhang, C., Ernst, M.D.: Automated documentation inference to explain failed tests. In: 2011 26th IEEE/ACM International Conference on Automated Software Engineering (ASE 2011), pp. 63–72. IEEE (2011) Zhang, S., Zhang, C., Ernst, M.D.: Automated documentation inference to explain failed tests. In: 2011 26th IEEE/ACM International Conference on Automated Software Engineering (ASE 2011), pp. 63–72. IEEE (2011)
Metadaten
Titel
Learning to Generate Comments for API-Based Code Snippets
verfasst von
Yangyang Lu
Zelong Zhao
Ge Li
Zhi Jin
Copyright-Jahr
2019
Verlag
Springer Singapore
DOI
https://doi.org/10.1007/978-981-15-0310-8_1

Premium Partner