Code Velocity
டெவலப்பர் கருவிகள்

செயல்பாட்டு மார்க் டவுன்: ஹக்கிங் ஃபேஸ் மூலம் ஆவண சோதனை புரட்சியை உருவாக்குதல்

·8 நிமிட வாசிப்பு·Hugging Face·அசல் மூலம்
பகிர்
குறியீட்டுத் துண்டுகள் மற்றும் 'செயல்பாட்டு' டேக்குடன் கூடிய ஹக்கிங் ஃபேஸ் லோகோ, செயல்பாட்டு மார்க் டவுன் எடுத்துக்காட்டுகளின் கருத்தை பிரதிபலிக்கிறது.

ஆவணங்கள் டெவலப்பர்களுக்கும் அவர்களின் கருவிகளுக்கும் இடையிலான ஒரு முக்கிய பாலமாக செயல்படுகின்றன, ஆனால் அதன் நம்பகத்தன்மை பெரும்பாலும் ஒரு பரவலான பிரச்சனையால் பாதிக்கப்படுகிறது: ஆவணச் சறுக்கல் (documentation drift). மென்பொருள் வளரும்போது, ஆவணங்களில் உள்ள குறியீட்டு எடுத்துக்காட்டுகள் அமைதியாக உடைந்து போகலாம், இது விரக்தி, நேர விரயம் மற்றும் நம்பிக்கையின் சரிவுக்கு வழிவகுக்கும். AI புதுமைகளில் ஒரு தலைவரான ஹக்கிங் ஃபேஸ், இந்த சவாலை தனது doc-builder திட்டம் மூலம் நேரடியாக எதிர்கொள்கிறது, இது செயல்பாட்டு மார்க் டவுன் தொகுதிகளை அறிமுகப்படுத்துகிறது, இது ஆவண எடுத்துக்காட்டுகள் விளக்கமளிப்பவையாக மட்டுமல்லாமல், கடுமையாக சோதிக்கப்படுவதையும் உறுதி செய்கிறது. இந்த நவீன அணுகுமுறை, செயல்படுத்தக்கூடிய ஆவணங்களை நாம் அணுகும் விதத்தை மறுவரையறை செய்கிறது, நல்ல ஆவணங்களின் தெளிவை தொடர்ச்சியான சோதனையின் வலுவான தன்மையுடன் இணைக்கிறது.

சவால்: ஆவணங்களுக்கும் குறியீட்டு ஒருமைப்பாட்டிற்கும் இடையே உள்ள இடைவெளியைக் குறைத்தல்

செயல்பாட்டு ஆவணங்களுக்குப் பின்னால் உள்ள அடிப்படை தத்துவம் புதியது அல்ல. பல தசாப்தங்களாக, பைத்தான் சமூகம் ஆவணங்களில் உள்ள எடுத்துக்காட்டுகளை பயனர்கள் நகலெடுத்து, ஒட்டி, குறைபாடின்றி இயங்கும் என்று எதிர்பார்க்கலாம் என்று வாதிட்டது. இருப்பினும், ஹக்கிங் ஃபேஸின் டிரான்ஸ்ஃபார்மர்கள் நூலகம் போன்ற பெரிய, வேகமாக வளர்ந்து வரும் திட்டங்களில் இந்த இலட்சியத்தைப் பராமரிப்பது ஒரு மாபெரும் பணியாகும். கைமுறை சரிபார்ப்பு நடைமுறைக்கு சாத்தியமற்றது, மேலும் பாரம்பரிய முறைகள் பெரும்பாலும் தெளிவான ஆவணங்களுக்கும் பயனுள்ள சோதனைக்கும் இடையே ஒரு சமரசத்தை வற்புறுத்துகின்றன.

இந்த பிரச்சனை அடிப்படை தேவைகளின் வேறுபாடுகளிலிருந்து எழுகிறது:

  • ஆவண எடுத்துக்காட்டுகள் சுருக்கம், படிக்கும் தன்மை மற்றும் கற்பிப்பதில் கவனம் செலுத்துவதற்கு முன்னுரிமை அளிக்கின்றன. அவை "குரலற்ற" இருக்க வேண்டும் என்று நோக்கமாகக் கொண்டுள்ளன.
  • சோதனைகள் உறுதிப்பாடுகள், அமைப்பு/பிரித்தல் (setup/teardown), ஃபிக்சர்கள், மோசடிகள் மற்றும் பிழைத்திருத்த திறன்களை கோருகின்றன. அவை வலுவான தன்மை மற்றும் கவரேஜுக்கு முன்னுரிமை அளிக்கின்றன.

இந்த இரண்டு கவலைகளும் ஒரே வடிவத்திற்குள் தள்ளப்படும்போது, ஒன்று பெரும்பாலும் பாதிக்கப்படுகிறது. ஹக்கிங் ஃபேஸின் doc-builder இந்த பதட்டத்தைத் தீர்க்க முற்படுகிறது, ஆவணங்கள் சுத்தமாக இருக்க அனுமதிக்கும் அதே வேளையில், அதன் அடிப்படை எடுத்துக்காட்டுகள் கடுமையாக சரிபார்க்கப்படுகின்றன, பயனர்கள் எதிர்கொள்ளும் ஒவ்வொரு துணுக்கும் சரிபார்க்கக்கூடிய உண்மை என்பதை உறுதிசெய்கிறது, ஒரு வெறும் இலக்கு அல்ல. AI இன் வேகமாக வளரும் உலகில் நம்பகத்தன்மையைப் பராமரிப்பதற்கும் டெவலப்பர் தத்தெடுப்பை விரைவுபடுத்துவதற்கும் இது மிக முக்கியம்.

doctest இன் மரபு: ஆரம்பகால கண்டுபிடிப்புகள் மற்றும் வளர்ந்து வரும் தேவைகள்

செயல்பாட்டு ஆவணங்களின் கருத்து பைத்தான் 2.1 (2001) இல் doctest அறிமுகப்படுத்தப்பட்டதன் மூலம் பைத்தான் சமூகத்தில் ஆரம்பகால ஈர்ப்பைப் பெற்றது. டிம் பீட்டர்ஸ் என்பவரால் உருவாக்கப்பட்ட doctest ஒரு நேர்த்தியான தீர்வாக இருந்தது: இது ஊடாடும் பைத்தான் இன்டர்பிரெட்டர் அமர்வுகள் (>>> add(2, 3)\n5) போல வடிவமைக்கப்பட்ட ஆவண எடுத்துக்காட்டுகளைப் பாகுபடுத்தியது மற்றும் வெளியீடு எதிர்பார்ப்புகளுடன் பொருந்துவதை சரிபார்த்தது. இந்த கண்டுபிடிப்பு, ஆவண எடுத்துக்காட்டுகளை தானியங்கு மறு ஆய்வு சோதனைகளாக (automatic regression tests) மாற்றியது, இது குறியீட்டு தரத்திற்கு ஒரு குறிப்பிடத்தக்க முன்னேற்றமாகும்.

doctest குறிப்பாக பைத்தானுக்கு நன்கு பொருந்திப் போனது, இது ஊடாடும் ஆய்வை ஊக்குவிக்கும் ஒரு மொழி. சிறிய திட்டங்கள் மற்றும் நேரடியான APIகளுக்கு, இது விதிவிலக்காக சிறப்பாக செயல்பட்டது, அடிப்படை எடுத்துக்காட்டுகள் செயல்படக்கூடியதாக இருப்பதை உறுதிசெய்ய ஒரு எளிய ஆனால் சக்திவாய்ந்த வழிமுறையை வழங்கியது. இது மென்பொருள் மேம்பாட்டில் "வெறும் சொல்லாதே, காட்டிக்காட்டு" என்ற உணர்வை உள்ளடக்கியது, ஆவணங்களை சோதனை தொகுப்பின் ஒரு செயலில் உள்ள பகுதியாக மாற்றியது.

ஹக்கிங் ஃபேஸின் நவீன தீர்வு: செயல்பாட்டு மார்க் டவுன் தொகுதிகள்

பெரிய அளவிலான, சிக்கலான திட்டங்களுக்கான பழைய அணுகுமுறைகளின் வரம்புகளை அங்கீகரித்து, ஹக்கிங் ஃபேஸின் doc-builder திட்டம் செயல்பாட்டு ஆவணங்களின் ஒரு அதிநவீன அணுகுமுறையை அறிமுகப்படுத்துகிறது. ஆவணத்தின் தொடரியல் அமைப்புக்குள் சோதனைகளை உட்பொதிப்பதற்குப் பதிலாக, இது ஆவண ஸ்னிப்பெட்டுகளை மார்க் டவுனுக்குள் இருக்கும் சாதாரண பைத்தான் குறியீடாகக் கருதுகிறது. இது மார்க் டவுனை ஒரு மெல்லிய சோதனை கண்டெய்னராக மாற்றி, விளக்கக்காட்சியை சோதனை வழிமுறைகளிலிருந்து பிரிக்கிறது.

மார்க் டவுனில் ஒரு செயல்பாட்டு தொகுதி இப்படித் தோன்றும்:

```py runnable:quickstart
from transformers import pipeline

pipe = pipeline("sentiment-analysis")
result = pipe("I love runnable docs!")

if not result:  # doc-builder: hide
    raise ValueError("pipeline returned no result")

print(result[0]["label"])
assert result[0]["score"] > 0.5  # doc-builder: ignore-bare-assert
```

ரெண்டர் செய்யப்படும்போது, இந்தத் தொகுதி ஒரு நிலையான குறியீட்டு எடுத்துக்காட்டாகத் தோன்றும். இருப்பினும், சோதனையின் போது, இது சாதாரண பைத்தான் குறியீடாக செயல்படுத்தப்படுகிறது. இந்த இரட்டை தன்மை, ஆவணங்கள் வாசகர்களுக்கு சுத்தமாக இருப்பதை உறுதிசெய்கிறது, அதே நேரத்தில் டெவலப்பர்களுக்கு வலுவான, சோதிக்கக்கூடிய எடுத்துக்காட்டுகளை வழங்குகிறது. இந்த அணுகுமுறை, AI போன்ற சிக்கலான களங்களுக்கு குறிப்பாக முக்கியமானது, இங்கு எடுத்துக்காட்டுகள் பெரும்பாலும் சிக்கலான மாதிரி ஏற்றுதல் மற்றும் அனுமான படிகளை உள்ளடக்கும்.

pytest மற்றும் மேம்பட்ட அம்சங்களுடன் தடையற்ற ஒருங்கிணைப்பு

ஹக்கிங் ஃபேஸின் அணுகுமுறையின் ஒரு முக்கிய வேறுபடுத்தும் அம்சம், pytest போன்ற நவீன சோதனை கட்டமைப்புகளுடன் அதன் தடையற்ற ஒருங்கிணைப்பு ஆகும். hf-doc-builder நிறுவப்பட்டிருக்கும் போது, pytest தானாகவே மார்க் டவுன் கோப்புகளுக்குள் உள்ள செயல்பாட்டு தொகுதிகளைக் கண்டறிந்து செயல்படுத்தலாம், ஒவ்வொரு தொகுதியையும் ஒரு நிலையான சோதனை உருப்படியாகக் கருதும். இதன் பொருள், ஆவண எடுத்துக்காட்டுகள் ஒரு திட்டத்தின் ஏற்கனவே உள்ள சோதனை உள்கட்டமைப்பில் முழுமையாக பங்கேற்க முடியும், pytest இன் சக்திவாய்ந்த அம்சங்களான உறுதிப்பாடுகள், ஃபிக்சர்கள், அலங்காரிகள் மற்றும் பிழைத்திருத்தக் கருவிகள் மற்றும் விரிவான அறிக்கையிடல் ஆகியவற்றை பயன்படுத்திக் கொள்ளலாம்.

செயல்படுத்தக்கூடிய ஆவணங்களின் பரிணாமம்: doctest Vs. doc-builder

அம்சம்doctest (பாரம்பரிய)doc-builder (நவீன செயல்பாட்டு மார்க் டவுன்)
சோதனை அணுகுமுறைஆவணங்களில் இன்டர்பிரெட்டர் அமர்வுகளாக சோதனைகளை உட்பொதிக்கிறதுஆவண துண்டுகளை சோதனைக்கான சாதாரண பைத்தான் குறியீடாக கருதுகிறது
ஒருங்கிணைப்புநிலையான நூலக தொகுதிதடையற்ற ஒருங்கிணைப்புக்கான pytest செருகுநிரல்
சோதனை தொடரியல்>>> தூண்டுதல்கள், எதிர்பார்க்கப்படும் வெளியீட்டுப் பொருத்தம்நிலையான பைத்தான் குறியீடு, pytest உறுதிப்பாடுகள்
நெகிழ்வுத்தன்மைவரையறுக்கப்பட்டது, எளிதில் உடையும் வெளியீட்டுப் பொருத்தம்அதிகம், சிக்கலான சோதனைகள், அலங்காரிகள், பிழைத்திருத்தத்தை ஆதரிக்கிறது
ஆவணச் சுத்தம்சோதனை வழிமுறைகளால் ஆவணங்களை குழப்பலாம்மறைக்கப்பட்ட கட்டளைகளுடன் சுத்தமான ஆவணங்களை பாதுகாக்கிறது
பிழைத்திருத்தம்சரம் ஒப்பீடு, குறைவான நேரடி ஆய்வுநிலையான பைத்தான் பிழைத்திருத்தம், முழுமையான ட்ரேஸ்பேக்குகள்
அமைப்பு/பிரித்தல்எடுத்துக்காட்டுகளுக்கு சத்தம் சேர்க்கலாம்தொடர்ச்சியான தொகுதிகளுடன் சூழலை திறம்பட நிர்வகிக்கிறது
உண்மையின் ஆதாரம்ஆவண வடிவம் மற்றும் உட்பொதிக்கப்பட்ட சோதனைகள்மார்க் டவுன் மூலம், நிலையான பைத்தான் செயல்படுத்தல் மூலம் சோதிக்கப்பட்டது

doc-builder தொடர்ச்சியான தொகுதிகளையும் (continuation blocks) அறிமுகப்படுத்துகிறது, இது பல படி பயிற்சிகளுக்கு ஒரு முக்கியமான அம்சமாகும். இவை ஆசிரியர்கள் ஒரு எடுத்துக்காட்டை runnable:test_basic அதைத் தொடர்ந்து runnable:test_basic:2 போன்ற பல புலப்படும் ஸ்னிப்பெட்டுகளாகப் பிரிப்பதற்கு அனுமதிக்கிறது. முக்கியமாக, இந்த தொகுதிகள் சோதனைகளின் போது ஒரே செயல்படுத்தல் சூழலைப் பகிர்ந்து கொள்கின்றன, இது அனைத்து குறியீடுகளையும் ஒரே நீண்ட தொகுதியில் கட்டாயப்படுத்தாமல் ஒரு இயற்கை கற்பித்தல் ஓட்டத்தை செயல்படுத்துகிறது. சிக்கலான AI மாதிரி பயன்பாடு அல்லது தரவு செயலாக்க பைப்லைன்கள் மூலம் பயனர்களுக்கு வழிகாட்டுவதற்கு இந்த நெகிழ்வுத்தன்மை முக்கியமானது.

உதாரணமாக, ஒரு AI முகவர் மேம்பாட்டு பணிப்பாய்வு பல படிகளை உள்ளடக்கும்: முகவரின் கருவிகளை வரையறுத்தல், முகவரை துவக்குதல், பின்னர் ஒரு வினவலை இயக்குதல். தொடர்ச்சியான தொகுதிகள் இந்த ஒவ்வொரு படிகளையும் தனித்தனி ஆவணப் பிரிவுகளில் தெளிவாக முன்வைக்க அனுமதிக்கின்றன, அதே நேரத்தில் ஒற்றை, ஒத்திசைவான சோதனை வரிசையாக செயல்படுத்தப்படுகின்றன, மேம்பட்ட முகவர் பணிப்பாய்வுகள் Operationalizing Agentic AI: Part 1 எவ்வாறு செயல்படுகின்றன என்பது போல.

வலுவான சோதனையை உறுதிசெய்யும் அதே வேளையில் சுத்தமான ஆவணங்களைப் பராமரித்தல்

doc-builder இன் மிக நேர்த்தியான தீர்வுகளில் ஒன்று, மூல மார்க் டவுன் சோதனைக்கு குறிப்பிட்ட கட்டளைகளைக் கொண்டிருந்தாலும், ரெண்டர் செய்யப்பட்ட ஆவணங்களை சுத்தமாக வைத்திருக்கும் அதன் திறன் ஆகும். டெவலப்பர்கள் # doc-builder: hide போன்ற கருத்துகளை செயல்படுத்தக்கூடிய வரிகளுக்கு உட்பொதிக்கலாம், அவை ஆவணங்களில் தோன்றக்கூடாது, அல்லது # doc-builder: ignore-bare-assert சோதனையின் ஒரு பகுதியாக இருக்கும் உறுதிப்பாடுகளுக்கு, ஆனால் அதன் கருத்து ரெண்டர் செய்யப்படக்கூடாது. இதேபோல், pytest அலங்காரிகள் (# pytest-decorator: ...) ரெண்டரிங் போது நீக்கப்படுகின்றன.

இது ஆவணங்கள் கற்பித்தல் மற்றும் தெளிவில் கவனம் செலுத்துவதை உறுதிசெய்கிறது, சோதனை போயிலர்ப்ளேட்டால் குழப்பமடையாமல். பயனர் தொடர்புடைய குறியீட்டை மட்டுமே பார்க்கிறார், அதே நேரத்தில் அடிப்படை அமைப்பு அதன் செயல்பாட்டிற்கு உத்தரவாதம் அளிக்கிறது. டெவலப்பர் கருவிகளின் ஆவணங்களுக்கு இந்த சமநிலை முக்கியமானது, இங்கு அழகியல் கவர்ச்சி மற்றும் முழுமையான சரியான தன்மை இரண்டும் மிக முக்கியம்.

பெரிய அளவிலான AI திட்டங்கள் மற்றும் அதற்கு அப்பால் உள்ள தாக்கம்

ஹக்கிங் ஃபேஸின் டிரான்ஸ்ஃபார்மர்கள் போன்ற பெரிய களஞ்சியங்களுக்கு, நூற்றுக்கணக்கான ஆவணப் பக்கங்கள் மற்றும் ஆயிரக்கணக்கான எடுத்துக்காட்டுகளுடன், இந்த அம்சம் மாற்றியமைக்கும் ஒன்றாகும். இது ஆவணச் சறுக்கலைத் தானியங்குபடுத்துகிறது, இல்லையெனில் மிகப்பெரிய கைமுறை முயற்சி தேவைப்படும் அல்லது உடைந்த எடுத்துக்காட்டுகளின் நிலையான ஓட்டத்திற்கு வழிவகுக்கும் ஒரு பிரச்சனை. செயல்பாட்டு ஆவணங்கள் ஆவணங்களையும் குறியீட்டுத் தளத்தையும் ஒத்திசைவாக வைத்திருக்க உதவுகிறது, கைமுறை மதிப்பாய்வு சாத்தியமற்றது என்ற அளவில் நம்பகத்தன்மையைப் பராமரிக்கிறது. இது Evaluating AI Agents for Production போன்ற AI சமூகத்தில் உள்ள பரந்த முயற்சிகளுடன் ஒத்துப்போகிறது, இது நம்பகத்தன்மையை உறுதி செய்கிறது.

செயல்பாட்டு ஆவணங்களை pytest மற்றும் அதிநவீன CI/CD பைப்லைன்களின் நவீன சகாப்தத்திற்கு கொண்டு வருவதன் மூலம், ஹக்கிங் ஃபேஸ் டெவலப்பர் அனுபவம் மற்றும் குறியீட்டு தரத்திற்கான சக்திவாய்ந்த உறுதிப்பாட்டை வெளிப்படுத்துகிறது. இருபது ஆண்டுகளுக்கும் மேலாக இருந்த அதே இலக்கு இன்னும் உள்ளது: ஆவண எடுத்துக்காட்டுகள் செயல்பட வேண்டும். ஆனால் இப்போது, அவை குறியீடு எப்படி செயல்பட வேண்டும் என்பதை விளக்குவது மட்டுமல்லாமல், அது செயல்படுகிறது என்பதை தொடர்ந்து நிரூபிக்கிறது, AI மேம்பாட்டிற்கான மிகவும் நம்பகமான மற்றும் நம்பகமான சூழல் அமைப்பை வளர்க்கிறது.

அடிக்கடி கேட்கப்படும் கேள்விகள்

What is the core problem Hugging Face's runnable Markdown addresses?
Hugging Face's runnable Markdown addresses the pervasive problem of 'documentation drift,' where code examples in documentation become outdated and silently break as libraries and APIs evolve. This leads to user frustration and diminishes the credibility of the documentation. By making documentation examples runnable and testable, the doc-builder ensures that these snippets are continuously validated against the codebase, guaranteeing that they always work as advertised. This proactive approach prevents broken examples, enhances user trust, and improves the overall developer experience by providing reliable resources.
How does runnable Markdown differ from Python's traditional `doctest` module?
While both `doctest` and runnable Markdown aim for executable documentation, they differ significantly in their approach. `doctest` embeds tests directly into documentation syntax, requiring examples to mirror interactive interpreter sessions with expected output. This often leads to documentation being cluttered with test mechanics. Hugging Face's runnable Markdown, in contrast, treats documentation snippets as normal Python code living within Markdown files. It integrates seamlessly with modern testing frameworks like `pytest`, allowing for complex assertions, debugging, and standard test infrastructure. This separation of concerns ensures documentation remains clean and readable, while testing remains powerful and flexible, avoiding the limitations of `doctest`'s brittle output matching and verbose setup/teardown.
What are 'continuation blocks' in Hugging Face's `doc-builder`?
Continuation blocks are a powerful feature in Hugging Face's `doc-builder` that allow authors to split complex code examples or tutorials across multiple visible Markdown snippets while maintaining a shared execution context during testing. This means that a setup defined in one runnable block can be reused and built upon in a subsequent block, without forcing the documentation to present everything as one long, monolithic code fence. For example, `runnable:test_basic` can define initial variables, and `runnable:test_basic:2` can then use those variables. This enhances readability and instructional flow in documentation, making it easier to present multi-step processes without sacrificing the integrity of the underlying testable code.
How does `doc-builder` integrate with existing testing frameworks like `pytest`?
Hugging Face's `doc-builder` integrates natively with `pytest`, transforming runnable Markdown blocks into standard `pytest` test items. With `hf-doc-builder` installed, `pytest` automatically discovers and executes these blocks within Markdown files. This integration means that documentation examples can leverage the full power of `pytest`, including its assertion mechanisms, fixtures, decorators, and debugging tools. Failures appear as normal test failures with comprehensive tracebacks, allowing developers to debug effectively. This approach avoids the need for a special-purpose testing mini-language, embedding documentation tests directly into the project's existing, robust test infrastructure.
How does `doc-builder` ensure documentation remains clean despite embedded test logic?
A key design principle of `doc-builder` is to prevent test mechanics from polluting the user-facing documentation. Authors can embed test-only directives, such as `# pytest-decorator: transformers.testing_utils.slow` or `# doc-builder: hide` for lines that should be executable but not displayed, directly within the Markdown source. When the documentation is rendered, `doc-builder` intelligently strips these directives and comments, presenting a clean, readable code snippet to the user. This allows developers to write comprehensive tests alongside their examples without compromising the clarity and brevity expected of good documentation, maintaining a clear separation between the source code for testing and the rendered content for users.
What are the benefits of runnable documentation for large AI projects like Hugging Face Transformers?
For large AI projects such as Hugging Face Transformers, which involve extensive documentation and thousands of code examples, runnable documentation offers immense benefits. It drastically reduces 'documentation drift' by continuously validating examples against the evolving codebase, ensuring they remain accurate and functional. This prevents user frustration caused by broken examples and builds trust in the documentation's reliability. By integrating with `pytest`, it allows these projects to manage documentation tests within their existing CI/CD pipelines, making manual review of examples unnecessary at scale. This automated validation is crucial for maintaining the quality and usability of documentation in rapidly developing and complex software ecosystems.
Can runnable Markdown be adopted by other projects outside of Hugging Face?
Yes, the principles and mechanisms behind Hugging Face's runnable Markdown, particularly its integration with standard Python testing tools like `pytest` and its focus on separating testing logic from displayed documentation, are highly applicable and beneficial for any software project. While the `doc-builder` itself is specific to Hugging Face, the underlying ideas represent a best practice in developer tools. Other projects can implement similar systems using existing tools or adapt `doc-builder`'s concepts to ensure their documentation examples are continuously tested and reliable. This approach is a general solution to a common problem across the software development landscape, making documentation more robust and trustworthy.

புதுப்பிப்புகளைப் பெறுங்கள்

சமீபத்திய AI செய்திகளை மின்னஞ்சலில் பெறுங்கள்.

பகிர்